ggplot2——玫瑰图

来源:互联网 发布:java字符串单词 编辑:程序博客网 时间:2024/04/29 06:29

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

1 0
原创粉丝点击