theme_set(主题名/自己折腾的主题变量) 相当于设置默认使用的主题; theme_update() 或 theme_replace() 分别对应覆写或替代,将后面的参数覆写或替代原主题的相关信息,具体区别见帮助文档; theme_get() 没搞明白,疯了,什么东西这是 help文档中对应介绍:Use theme_get() to get the current theme…… 微调 ...
p+theme_bw()+labs(subtitle="Change theme_bw") ggplot2 扩展包主题 代码语言:javascript 复制 library(ggthemes)p+theme_economist()+labs(subtitle="Change theme_economist")#其他可选#theme_economist theme_economist_white theme_wsj theme_excel theme_few #theme_foundation theme_igray theme_solarized th...
再来使用theme_replace修改主题(在此之前我们先恢复旧的主题): theme_set(old) print(p) theme_replace(panel.grid = element_line(color = "red")) new_replace <- theme_get() print(p) 可以看到,以上两种方式都成功将网格线的颜色设置为了红色,但是theme_replace却将虚线改为了实线,这是为什么呢?我们先...
theme_update()函数是一种增量更新,也即在默认主题的基础上,对比与theme_update()函数内部各个主题参数之间的差异,有差异的以新增的为主,无差异的则保持不变。 而theme_replace()函数则更为霸道,它是一种全量更新,即在默认主题的基础上,比对与theme_replace()函数内部主题参数之间的差异,有差异则以后者为准,但是...
# Setupoptions(scipen=999)library(ggplot2)data("midwest",package="ggplot2")theme_set(theme_bw())# Add plot components ---gg<-ggplot(midwest,aes(x=area,y=poptotal))+geom_point(aes(col=state,size=popdensity))+geom_smooth(method="loess",se=F)+xlim(c(0,0.1))+ylim(c(0,500000))+la...
有一些本应属于主题类的东西不能在theme_set 函数中设置,需要使用特殊的函数,如坐标轴翻转、刻度设置等,在这不再介绍。如果想比较透彻的学习,建议把ggplot2项目从GitHub克隆下来研究 它的代码。更好的方法是研究ggmap和ggbio这两个包,它们的代码本身就是ggplot2应用的最好范例。尤其是ggmap,H.W.是它的作者之 一...
theme是解决图是否美观的一个工具,其与scale最大的区别在于不受数据左右。先把scale做好,就是一张合格的图;再处理theme,则是一张出色的图。 载入数据,R包 library(ggplot2)#载入数据data(diamonds)set.seed(1234)diamond <- diamonds[sample(nrow(diamonds), 2000), ]# 绘制初始图形p <- ggplot(data = dia...
主题(Theme) 二 数据(data) 和 映射(Mapping) 数据:用于绘制图形的数据,本文主要使用经典的mtcars数据集和diamonds数据集子集为例来画图。 #install.packages("ggplot2") library(ggplot2) data(diamonds) set.seed(1234) diamond<-diamonds[sample(nrow(diamonds),2000), ] ...
主题(Theme) 二 数据(data) 和 映射(Mapping) 数据:用于绘制图形的数据,本文主要使用经典的mtcars数据集和diamonds数据集子集为例来画图。 AI检测代码解析 #install.packages("ggplot2") library(ggplot2) data(diamonds) set.seed(1234) diamond <- diamonds[sample(nrow(diamonds), 2000), ] ...
>theme_set(theme_bw()) >p+geom_point() 如果还要建立其他映射,比如用钻石颜色(color)分类数据确定点的颜色,图形外观就会发生变化: >p+geom_point()+aes(color=color)+theme(legend.position=c(2,2)) ggplot2映射的过程可以用plot函数作图步骤进行分解,它包含三方面的操作...