您的位置:首页 > 其它

ggplot2——玫瑰图

2015-08-13 23:18 381 查看
更多内容请见:R、ggplot2、shiny 汇总

初始图样:

library(ggplot2)
dt = data.frame(A = c(2, 7, 4, 10, 1), B = c('B','A','C','D','E'))
windowsFonts(myFont = windowsFont("楷体"))   ## 绑定字体

p = ggplot(dt, aes(x = B, y = A, fill = B)) + 
  geom_bar(stat = "identity", alpha = 0.7) + 
  coord_polar() 
p






修补过后的玫瑰图:

library(ggplot2)
dt = data.frame(A = c(2, 7, 4, 10, 1), B = c('B','A','C','D','E'))
windowsFonts(myFont = windowsFont("楷体"))   ## 绑定字体

p = ggplot(dt, aes(x = B, y = A, fill = B)) + 
  geom_bar(stat = "identity", alpha = 0.7) + 
  coord_polar() + 
  theme_bw() + 
  labs(x = "", y = "", title = "这个玫瑰图有点丑") + 
  geom_text(aes(y = A/2 + max(A)/4, label = A, color = B), size = 5) +    ## 加上数字
  theme(axis.text.y = element_blank()) +    ## 去掉左上角的刻度标签
  theme(axis.ticks = element_blank()) +    ## 去掉左上角的刻度线
  theme(panel.border = element_blank()) +   ## 去掉外层边框
  theme(legend.position = "none") +   ## 去掉图例
  theme(title = element_text(vjust = -56, face = "bold", family = "myFont"))   ## 将图例移到图的下方,并更改一下字体格式
p




注:更多修改的细节可见:ggplot2——饼图篇,两者类似。





转载请注明出处,谢谢!(原文链接:http://blog.csdn.net/Bone_ACE/article/details/47624987
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: