ggplot2——玫瑰图

更多内容请见: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

ggplot2——玫瑰图_第1张图片


修补过后的玫瑰图:

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——玫瑰图_第2张图片

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



转载请注明出处,谢谢!(原文链接:http://blog.csdn.net/Bone_ACE/article/details/47624987)

你可能感兴趣的:(r,ggplot2,作图,玫瑰图)