|
发表于 2022-9-29 23:44:21
|
查看: 1165 |
回复: 0
一、小提琴图
- #小提琴图
- ggplot(data = ToothGrowth,aes(x=supp,y=len,fill=supp))+geom_violin()
- ToothGrowth$dose <- as.factor(ToothGrowth$dose)
- ggplot(data = ToothGrowth,aes(x=supp:dose,y=len,fill=supp))+geom_violin()
- #小提琴图+箱线图
- ggplot(data = ToothGrowth,aes(x=supp:dose,y=len,fill=supp))+geom_violin()+
- geom_boxplot(width=0.1,fill="white")
- #两组小提琴图
- ggplot(data = ToothGrowth,aes(x=dose,y=len,group=supp:dose,fill=supp:dose))+
- geom_violin()
复制代码
利用 ggplot2 绘制小提琴图
二、修改主题
- mtcars$cyl <- as.factor(mtcars$cyl)
- p <- ggplot(mtcars, aes(x=wt, y=mpg, color=cyl)) +geom_point(size=3)
- p
- p + theme(legend.position = 'top')
- p + theme(legend.position = 'top',legend.background = element_rect(fill = 'red'))
- p + theme(legend.position = 'top',legend.background = element_rect(color = 'red'))
- #去除图例
- # p+guides(fill='none')
- p+theme(legend.position = "none")
- # p+scale_fill_discrete(guide='none')
- #改图例标题文本
- p +theme(legend.title = element_blank())
- p +theme(legend.title = element_text(size = 2))
- p +theme(legend.title = element_text(size = 22))
- p +theme(legend.title = element_text(size = 22,colour = 'red'))
- #改坐标轴
- p+theme(axis.title = element_blank())
- p+theme(axis.title.x = element_blank())
- p+theme(axis.title.x = element_text(size = 22,angle = 90))
- p+theme(axis.title.x = element_text(size = 22,colour = 'red'))
- p+theme(axis.title = element_text(size = 22,colour = 'red'))
- #改图例类目文本
- p+theme(legend.text = element_blank())
- p+theme(legend.text = element_text(colour = 'red'))
- #画方格线
- p+theme(panel.grid = element_line(colour = "red"))
- p+theme(panel.grid.major = element_line(colour = "red"))
- p+theme(panel.grid.minor = element_line(colour = "red"))
- p+theme(panel.grid.minor.x = element_line(colour = "red"))
复制代码
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
|