r - 条形图定制

标签 r

所以我有这个数据表

   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)
)

输出此条形图 enter image description here

现在我想绘制这个条形图,将图例放在条形图之外,并将字母 w1、w2、w3、w4... 旋转 45 度。:

enter image description here

上面的图片是在 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)

enter image description here

关于r - 条形图定制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32678197/

相关文章:

r - 如何从多个向量中找到共同元素?

减少 R 中的行数

r - Shiny 模块中带有反应输入的启动警告

r - 修复数据框中的混合日期格式?

r - 在大型数据框中重新排序列

r - 在ggplot2中的不同等高线图中保持相同的中断

r - 使用本地数据集部署 Shiny 的应用程序

r - *.o : File format not recognized on Windows 7

r - [R] 中的条件分组和汇总数据框

r - 使用 ggdendro 在树状图的片段下显示变量标签