gpt4 book ai didi

r - 带有灰色和黑色虚线的线图

转载 作者:行者123 更新时间:2023-12-04 23:42:21 25 4
gpt4 key购买 nike

使用 ggplot2 R 包,我用 6 条彩色线(指一个因子的 6 个级别)制作了一个线图,我想将其更改为黑色和白色,制作 3 条黑色实线、点划线和 3 条灰色实线,虚线和虚线。
我尝试使用 scale_linetype_manual() 和 scale_color_grey() 但我无法混合灰色和黑色虚线。

这里是比例灰度选项的代码:

ggplot() + 
geom_line(data = f[!is.na(f$fr),], aes(x=date2, y=fr, colour=locality, group=locality),
size = 1.0) +
scale_color_grey(start = 0, end = 0.9, guide="legend", name="Locality",
labels=c("a","b","c","d","e","f")) +
xlab("") +
ylab("") +
theme_bw() +
theme(legend.position = "top", panel.background = element_rect(fill = "white"),
panel.grid.major = element_line(colour = "white"),
axis.text.x=element_text(angle=90,hjust=1,vjust=0.5)) +
facet_grid(.~year)

enter image description here

虽然这是带虚线的代码:
ggplot() + 
geom_line(data = f[!is.na(f$fr),], aes(x=date2, y=fr, linetype=locality, group=locality),
size = 1.0) +
scale_linetype_manual(name="Locality",
values=c("solid", "dashed", "dotted", "dotdash", "longdash", "twodash"),
labels=c("a","b","c","d","e","f")) +
xlab("") +
ylab("") +
theme_bw()+
theme(legend.position = "top", panel.background = element_rect(fill = "white"),
panel.grid.major = element_line(colour = "white"),
axis.text.x=element_text(angle=90,hjust=1,vjust=0.5)) +
facet_grid(.~year)

enter image description here

所以..有人可以帮助我用一条黑色实线、一条黑色虚线、一条黑色虚线、一条灰色实线等创建同样的情节吗?

最佳答案

映射到两者 colourlinetype ,并设置手动比例。

d <- data.frame(locality = rep(letters[1:6], each = 2),
x = 1:2,
y = rep(1:6, each = 2))

ggplot(d, aes(x = x, y = y,colour = locality, linetype = locality)) +
geom_line() +
theme_bw() +
scale_color_manual(name = "Locality",
values = c('black', 'black', 'black', 'grey', 'grey', 'grey'),
labels = c("a","b","c","d","e","f")) +
scale_linetype_manual(name = "Locality",
values = c("solid", "dashed", "dotted", "solid", "dashed", "dotted"),
labels = c("a","b","c","d","e","f"))

enter image description here

关于r - 带有灰色和黑色虚线的线图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34021343/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com