我想为 Markdown 文档中构建的每个绘图定义一个调色板。本质上,这将覆盖默认选择。
有几个非常古老的答案 - 感谢@dww建议的此处和此处的链接- 解决了旧版本的问题(特别是在现代发布了几个主要版本(目前为 3.2.x)时,在 0.8.2 上提出了解决方案) )。
我将说明最接近的用例,设置主题。对于通用主题,这是微不足道的:+ theme_minimal()我可以设置在所有绘图中持续存在的主题,而不是附加在每个绘图上。
library(ggplot2)
d <- diamonds[sample(1:nrow(diamonds), 1000), ]
## without theming
ggplot(d, aes(x=carat, y=price, color=clarity)) +
geom_point() +
theme_minimal() # must set this theme call for every plot
## setting theme
theme_set(theme_minimal())
ggplot(d, aes(x=carat, y=price, color=clarity)) +
geom_point() # plot in theme, for all subsequent plots
Run Code Online (Sandbox Code Playgroud)
是否存在类似的修改来设置整个调色板?例如,基于主题的呼叫替换,
ggplot(d, aes(x=carat, y=price, color=clarity)) +
geom_point() +
scale_color_brewer(palette='Set2') # requesting a global option to …Run Code Online (Sandbox Code Playgroud) 我挣扎与data.table .SD电话.
特别是,我试图在一组数据中识别一些逻辑特征,并在另一个变量中绘制一些识别标记.规范应用.SD,对吧?
从FAQ 4.5,http://cran.r-project.org/web/packages/data.table/vignettes/datatable-faq.pdf,想象下表:
library(data.table) # 1.9.5
DT = data.table(a=rep(1:3,1:3),b=1:6,c=7:12)
DT[,{ mySD = copy(.SD)
mySD[1, b := 99L]
mySD },
by = a]
## a b c
## 1: 1 99 7
## 2: 2 99 8
## 3: 2 3 9
## 4: 3 99 10
## 5: 3 5 11
## 6: 3 6 12
Run Code Online (Sandbox Code Playgroud)
我已将这些值分配给b(使用':='运算符),因此当我重新调用DT时,我期望输出相同.但是,出乎意料的是,我遇到了原始表:
DT
## a b c
## 1: 1 1 7
## 2: 2 2 8 …Run Code Online (Sandbox Code Playgroud)