所以我有这个数据表
AA BB CC DD
W1 3.5 3.5 3.4 3.5
w2 3.4 3.7 3.6 3.5
w3 3.5 3.4 3.5 3.5
w4 3.5 3.4 3.5 3.5
w5 3.5 3.4 3.5 3.5
w6 3.5 3.4 3.5 3.5
w7 3.5 3.4 3.5 3.5
w8 3.5 3.4 3.5 3.5
和代码
qw<-barplot(as.matrix(t(tabela.matrix1)), beside=TRUE,
col=c("yellow", "cornflowerblue", "yellowgreen","orchid4"))
text(qw, 0, round(as.matrix(t(tabela.matrix1)), 1),cex=1,pos=3,srt=90)
#legend("bottom",
# c("AA","BB","CC", "DD"),
# fill=terrain.colors(4)
)
现在我想绘制这个条形图,将图例放在条形图之外,并将字母 w1、w2、w3、w4... 旋转 45 度。:
上面的图片是在 Excel 中创建的。
最佳答案
尽管分面也能发挥作用,但也可以将条形变小。当然可以调整条形和文本的躲避:
ggplot(xym, aes(x = Var1, y = value, fill = Var2)) +
theme_bw() +
scale_fill_brewer(palette = "Set1") +
theme(legend.position = "bottom", axis.text.x = element_text(angle = 90,vjust = 0.2)) +
geom_bar(stat = "identity", width = 0.7, position = position_dodge(width=0.7)) +
geom_text(aes(x = Var1, y = 0.05, label = round(value, 2), fill = Var2),
angle = 90, position = position_dodge(width = 0.7), size = 4)
关于r - 条形图定制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32678197/