简体   繁体   English

在R中设置调色板

[英]Setting color palette in R

I have been trying to produce a plot in just grayscale for the confidence interval fill and black lines for the predicted lines. 我一直在尝试为置信区间填充生成仅灰度的图,为预测线生成黑线。 I have tried every lead I find online and so far it has not produced a plot in grayscale. 我已经尝试了所有在网上找到的潜在客户,但到目前为止,它还没有绘制出灰度图。 Much obliged for any help. 非常有必要提供任何帮助。

For reference, Predictor 1 is a categorical variable (3 levels) and Predictor 2 is a continuous predictor variable. 作为参考,预测变量1是分类变量(3个级别),预测变量2是连续的预测变量。

library(ggthemes)
ggplot() +
geom_ribbon(data=yhat, aes(x=Predictor2, ymax=fit+se*1.96, 
ymin=fit-se*1.96, fill=Predictor1), alpha=0.5)+ geom_line(data=yhat,
aes(Predictor2, fit, color=Predictor1), size=1.5)
+xlab('') + ylab('') + ggtitle('')+
theme_few(base_size=14)+ scale_y_continuous(limits=c(0,1))+
geom_abline(aes(intercept=0.5,slope=0),linetype="dashed")

you can create your own pallette for ggplot 您可以为ggplot创建自己的调色板

pallette_yellow_green <- c("#ffff00", "#d4e100", "#bfd300", "#95b500", "#80a600", "#6a9700", "#558800", "#2b6b00", "#155c00", "#003400")

and then 接着

 ggplot()+scale_fill_manual(values = pallette_yellow_green)

how to find color codes? 如何找到颜色代码? use for example http://www.colorhexa.com/ (go for gradient generator) 例如使用http://www.colorhexa.com/ (用于渐变生成器)

that settles the issue for discrete variable 解决了离散变量的问题

for continuous variables scale_fill_continuous or scale_fill_gradient should set you up: http://docs.ggplot2.org/0.9.3.1/scale_gradient.html 对于连续变量scale_fill_continuousscale_fill_gradient应该设置您: http : scale_fill_gradient

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM