我已经搜索了答案,但是无法解决在R中标记条形图的问题。 所以我想在条形图的顶部显示频率,这可行,但是它们之间的位置不同。当然,我想在中间显示它们
png ("Studiengang.png", width = 600, height = 500)
par(mar = c (8, 5, 2, 2))
barplot (table$SG_A[1:7], names = table$SG[1:7], ylim = c (0, 50), las=2, ylab = "Anteil [%]")
text(table$SG_A[1:7], labels=table$SG_A[1:7], pos = 3, cex = 0.8 , col = "black")
box()
dev.off()
我需要更改什么?非常感谢您的帮助!
dput(table)
structure(list(GES = structure(c(4L, 3L, 2L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L), .Label = c("", "k.A / Sonst.", "männlich",
"weiblich"), class = "factor"), GES_A = c(89.66, 8.05, 2.3, NA,
NA, NA, NA, NA, NA, NA, NA, NA), SG = structure(c(3L, 2L, 6L,
4L, 7L, 8L, 5L, 1L, 1L, 1L, 1L, 1L), .Label = c("", "Erziehungsw.",
"Lehramt", "Psychologie", "Sonstige", "SOP", "UNN", "UWS"), class = "factor"),
SG_A = c(41.24, 21.65, 10.31, 3.09, 2.06, 2.06, 9.28, NA,
NA, NA, NA, NA), SEM = 1:12, SEM_A = c(3.45, 24.14, 4.6,
34.48, 2.3, 17.24, 3.45, 5.75, 0, 2.3, 1.15, 1.15), WOHN = structure(c(7L,
5L, 3L, 2L, 8L, 4L, 6L, 1L, 1L, 1L, 1L, 1L), .Label = c("",
"Alleine", "Eltern", "Familie", "Partner", "Sonstige", "WG",
"Wohnheim"), class = "factor"), WOHN_A = c(39.08, 22.99,
13.79, 8.05, 8.05, 6.9, 1.15, NA, NA, NA, NA, NA), KLASSE_B = structure(c(6L,
7L, 2L, 3L, 4L, 5L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("",
"gelegentlich", "häufig", "immer", "k.A.", "nie", "selten"
), class = "factor"), MEHRWEG = c(43.68, 6.9, 4.6, 3.45,
4.6, 36.78, NA, NA, NA, NA, NA, NA), PFAND = c(42.53, 5.75,
3.45, 4.6, 3.45, 40.23, NA, NA, NA, NA, NA, NA), EINWEG = c(21.84,
6.9, 3.45, 13.79, 14.94, 39.08, NA, NA, NA, NA, NA, NA),
KLASSE_M = structure(c(5L, 6L, 2L, 3L, 4L, 1L, 1L, 1L, 1L,
1L, 1L, 1L), .Label = c("", "gelegentlich", "häufig", "immer",
"nie", "selten"), class = "factor"), FUSS = c(27.59, 24.14,
16.09, 17.24, 14.94, NA, NA, NA, NA, NA, NA, NA), RAD = c(43.68,
13.79, 17.24, 20.69, 4.6, NA, NA, NA, NA, NA, NA, NA), OEFF = c(16.09,
14.94, 18.39, 33.33, 17.24, NA, NA, NA, NA, NA, NA, NA),
AUTO = c(40.23, 28.74, 12.64, 11.49, 6.9, NA, NA, NA, NA,
NA, NA, NA), MUELLTRENN = structure(c(2L, 3L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("", "ja", "nein"), class = "factor"),
MUELLTRENN_ZU = c(97.7, 2.3, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA), MUELLTRENN_UNI = c(67.82, 32.18, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA), Z_GELB = c(96.47, 3.53, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA), Z_REST = c(95.29, 4.71,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA), Z_BIO = c(72.94,
27.06, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA), Z_PAPIER = c(1L,
0L, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA), Z_GLAS = c(92.94,
7.06, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA), Z_SONST = c(10.59,
89.41, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA), ZU_CAM = c(97.7,
2.3, 67.82, 32.18, NA, NA, NA, NA, NA, NA, NA, NA), MUELLTRENN_G = structure(c(1L,
2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L), .Label = c("ja",
"nein"), class = "factor"), ZUHAUSE = c(95.29, 4.71, 72.94,
27.06, 100, 0, 96.47, 3.53, 92.94, 7.06, 10.59, 89.41), C_GELB = c(70L,
30L, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA), C_REST = c(93.33,
6.67, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA), C_BIO = c(40L,
60L, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA), C_PAPIER = c(83.33,
16.67, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA), C_GLAS = c(26.67,
73.33, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA), C_SONST = c(1.67,
98.33, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA), CAMPUS = c(93.33,
6.67, 40, 60, 83.33, 16.67, 70, 30, 26.67, 73.33, 1.67, 98.33
)), class = "data.frame", row.names = c(NA, -12L))
答案 0 :(得分:1)
这是一种可能的解决方案:
barplotData <- c(barplot(table$SG_A[1:7], names = table$SG[1:7]) ) # saves x positions
您需要指定在钢筋高度上方应该有多少空间(y = 2 + SG_A)
par(mar = c (8, 5, 2, 2))
barplot (table$SG_A[1:7], names = table$SG[1:7], ylim = c (0, 50), las=2, ylab = "Anteil [%]")
text(x=barplotData, y= 2 + table$SG_A[1:7], labels=table$SG_A[1:7])
box()