我正在创建一个图,描述每个人(“病人”)的几个数据点(“区域”)。我正在尝试将表示这些区域的颜色设置为手动的色盲友好调色板:
#data sample
patient <- c("pat1", "pat1", "pat1", "pat1", "pat1", "pat1", "pat2", "pat2", "pat2", "pat2", "pat2", "pat2") %>% as.factor()
region <- c("bg", "cb", "fr", "hc", "sn", "th", "bg", "cb", "fr", "hc", "sn", "th")
abundance <- c(0.00257, 0.00172, 0.0214, 0.00594, 0.00151, 0.00955, 0.00257, 0.00172, 0.0214, 0.00594, 0.00151, 0.00955)
errormax <- c(0.00569, 0.00435, 0.0378, 0.0131, 0.00507, 0.0194, 0.00569, 0.00435, 0.0378, 0.0131, 0.00507, 0.0194)
errormin <- c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
mydata <- tibble(patient, region, abundance, errormax, errormin)
#palette
cbbPalette <- c("#E69F00", "#56B4E9", "#009E73", "#0072B2", "#D55E00", "#CC79A7")
#plot
myplot <- ggplot(mydata, mapping = aes(x = patient, y = abundance, colour = region)) +
geom_point(position = position_dodge(width = 0.6), na.rm = TRUE) +
geom_errorbar(aes(ymin = errormax, ymax = errormin), width = 0.2, position = position_dodge(width = 0.6)) +
ylim(0,0.12)+
xlab("Patient") + ylab("Abundance") +
theme_bw() +
scale_colour_discrete(name="Brain region",
labels = c("basal ganglia", "cerebellum", "frontal cortex", "hippocampus", "midbrain", "thalamus"),
breaks = c("bg", "cb", "fr", "hc", "sn", "th"),
values = cbbPalette)
但是上面的代码给了我一个错误:
Error in discrete_scale(aesthetics, "hue", hue_pal(h, c, l, h.start, direction), :
unused argument (values = c("#E69F00", "#56B4E9", "#009E73", "#0072B2", "#D55E00", "#CC79A7"))
也许values
不是正确的论点?我应该用不同的东西代替吗?
发布于 2021-02-09 09:06:58
你可能需要scale_colour_manual
。
library(ggplot2)
ggplot(mydata, mapping = aes(x = patient, y = abundance, colour = region)) +
geom_point(position = position_dodge(width = 0.6), na.rm = TRUE) +
geom_errorbar(aes(ymin = errormax, ymax = errormin), width = 0.2,
position = position_dodge(width = 0.6)) +
ylim(0,0.12)+
xlab("Patient") + ylab("Abundance") +
theme_bw() +
scale_colour_manual(name="Brain region",
labels = c("basal ganglia","cerebellum","frontal cortex",
"hippocampus", "midbrain", "thalamus"),
breaks = c("bg", "cb", "fr", "hc", "sn", "th"),
values = cbbPalette)
https://stackoverflow.com/questions/66115833
复制相似问题