R语言由league绘制分面
libary(plyr) # Needed for desc()
library(gcookbook) # For the data set
tophit <- tophitters2001[1:30, ] # Take the top 30 from the tophitters data set
nameorder <- tophit$name[order(tophit$lg, tophit$avg)]
tophit$name <- factor(tophit$name, levels=nameorder)
ggplot(tophit, aes(x=avg, y=name)) +
geom_segment(aes(yend=name), xend=0, colour="grey50") +
geom_point(size=3, aes(colour=lg)) +
scale_colour_brewer(palette="Set1", limits=c("NL","AL"), guide=FALSE) +
theme_bw() +
theme(panel.grid.major.y = element_blank()) +
facet_grid(lg ~ ., scales="free_y", space="free_y")

修改颜色为oranges
ggplot(tophit, aes(x=avg, y=name)) +
geom_segment(aes(yend=name), xend=0, colour="grey50") +
geom_point(size=3, aes(colour=lg)) +
scale_colour_brewer(palette="Oranges", limits=c("NL","AL"), guide=FALSE) +
theme_bw() +
theme(panel.grid.major.y = element_blank()) +
facet_grid(lg ~ ., scales="free_y", space="free_y")

在主题添加了axis.text.x = element_text(angle=60, hjust=TRUE),axis.text.y = element_text(angle=30, hjust=TRUE)这一属性,颜色改成Pink
libary(plyr) # Needed for desc()
library(gcookbook) # For the data set
tophit <- tophitters2001[1:30, ] # Take the top 30 from the tophitters data set
nameorder <- tophit$name[order(tophit$lg, tophit$avg)]
tophit$name <- factor(tophit$name, levels=nameorder)
ggplot(tophit, aes(x=avg, y=name)) +
geom_segment(aes(yend=name), xend=0, colour="grey50") +
geom_point(size=3, aes(colour=lg)) +
scale_colour_brewer(palette="Oranges", limits=c("NL","AL"), guide=FALSE) +
theme_bw() +
theme(axis.text.x = element_text(angle=60, hjust=TRUE),axis.text.y = element_text(angle=30, hjust=TRUE),panel.grid.major.y = element_blank()) +
facet_grid(lg ~ ., scales="free_y", space="free_y")

参考文献:Practical Receipes for Visualizing Data----R Graphics Cookbook —Winston Chang O’REILLY
- 点赞
- 收藏
- 关注作者
评论(0)