2014-10-31 84 views
0

嗨,我想在barchart的两个面板中添加不同的文本。这两个文本值表示barchart中0值的百分比。我一直在寻找不同的帮助网站,但还没有找到答案。这里是我的尝试:向条形图中的面板添加不同的文本

数据

dput(ztable) 
structure(list(Group.1 = structure(c(1L, 2L, 3L, 4L, 5L, 6L, 
7L, 8L, 9L, 11L, 12L, 14L, 17L, 19L, 29L, 115L, 1L, 2L, 3L, 4L, 
5L, 6L, 7L, 8L, 9L, 11L, 12L, 14L, 17L, 19L, 29L, 115L), .Label = c("0", 
"10", "20", "30", "40", "50", "60", "70", "80", "90", "100", 
"110", "120", "130", "140", "150", "160", "170", "180", "190", 
"200", "210", "220", "230", "240", "250", "260", "270", "280", 
"290", "300", "310", "320", "330", "340", "350", "360", "370", 
"380", "390", "400", "410", "420", "430", "440", "450", "460", 
"470", "480", "490", "500", "510", "520", "530", "540", "550", 
"560", "570", "580", "590", "600", "610", "620", "630", "640", 
"650", "660", "670", "680", "690", "700", "710", "720", "730", 
"740", "750", "760", "770", "780", "790", "800", "810", "820", 
"830", "840", "850", "860", "870", "880", "890", "900", "910", 
"920", "930", "940", "950", "960", "970", "980", "990", "1000", 
"1010", "1020", "1030", "1040", "1050", "1060", "1070", "1080", 
"1090", "1100", "1110", "1120", "1130", "1140"), class = "factor"), 
    Group.2 = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
    2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("Fall", "Spring" 
    ), class = "factor"), x = c(677L, 344L, 18L, 6L, 5L, 4L, 
    0L, 2L, 0L, 1L, 0L, 0L, 1L, 1L, 0L, 1L, 82L, 186L, 15L, 6L, 
    8L, 1L, 3L, 0L, 1L, 1L, 1L, 1L, 0L, 0L, 1L, 0L)), .Names = c("Group.1", 
"Group.2", "x"), row.names = c(NA, -32L), class = "data.frame") 

条形图代码

​​

回答

0

你只需要在你的panel.text()功能的小错误。 x和y坐标使其无法读取文本。 barchart(这是panel.text函数中的第一个数字)中的x坐标是指小节编号。你有1,把它放在中间。 y coordiante指的是y轴上的值。这是您的panel.text' function. It is currently 0, but 400 works better. So replace your panel.text`行的第二个数字与此:

panel.text(8,400,labels=mytext[panel.number()]) } 

,你会得到:

enter image description here

+0

非常感谢你。我不明白在panel.text中x和y是什么意思。 – user41509 2014-11-03 16:15:51

相关问题