-
Notifications
You must be signed in to change notification settings - Fork 552
/
Copy path图3-6-2 南丁格尔玫瑰图系列.R
59 lines (49 loc) · 2.4 KB
/
图3-6-2 南丁格尔玫瑰图系列.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#EasyCharts团队出品,
#如有问题修正与深入学习,可联系微信:EasyCharts
library(ggplot2)
#----------------------------------单数据系列极坐标柱形图-----------------------------------------
mydata <- data.frame( a=c("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"),
b=c(50, 60, 70, 20,90,110,30))
myAngle <-seq(-20,-340,length.out =7)
ggplot(mydata) +
geom_bar(aes(x=a, y=b),width = 1,stat="identity",
colour = "black",fill="#F8766D") +
geom_text(aes(x=a,y = b-8,label = b),color="white") +
coord_polar(theta = "x",start=0) +
ylim(c(0,120))+
theme_light()+
theme( panel.background = element_blank(),
panel.grid.major = element_line(colour = "grey80",size=.25),
axis.text.y = element_text(size = 12,colour="black"),
axis.line.y = element_line(size=0.25),
axis.text.x=element_text(size = 13,colour="black",angle = myAngle))
#--------------------------------多数据系列极坐标柱形图-------------------------------------------
diamonds<-cbind(diamonds,Cou=rep(1,nrow(diamonds)))
sum_clarity<-aggregate(Cou~clarity,diamonds,sum)
sort_clarity<-arrange(sum_clarity,desc(Cou))
diamonds$clarity<- factor(diamonds$clarity, levels = sort_clarity$clarity)
myAngle <-seq(-20,-340,length.out = 8)
ggplot(diamonds,aes(x=clarity,fill=color))+
geom_bar(width=1.0,colour="black",size=0.25)+
coord_polar(theta = "x",start=0)+
scale_fill_brewer(palette="GnBu")+
guides(fill=guide_legend(reverse=TRUE,title=NULL))+
ylim(c(0,12000))+
theme_light()+
theme( panel.background = element_blank(),
panel.grid.major = element_line(colour = "grey80",size=.25),
axis.text.y = element_text(size = 12,colour="black"),
axis.line.y = element_line(size=0.25),
axis.text.x=element_text(size = 13,colour="black",angle = myAngle))
ggplot(diamonds,aes(x=clarity,fill=color))+
geom_bar(width=1.0,colour="black",size=0.25)+
coord_polar(theta = "x",start=0)+
scale_fill_brewer(palette="Reds")+
guides(fill=guide_legend(reverse=TRUE,title="Color"))+
ylim(c(-2000,12000))+
theme_light()+
theme( panel.background = element_blank(),
panel.grid.major = element_line(colour = "grey80",size=.25),
axis.text.y = element_text(size = 12,colour="black"),
axis.line.y = element_line(size=0.25),
axis.text.x=element_text(size = 13,colour="black",angle = myAngle))