在 R 中,散点图和平滑器按因子(颜色 = 因子)拆分,但我希望线条因灰度或线型而不是颜色而异
In R, scatterplot and smoother are split by factor (colour = factor), but I want the lines to differ by greyscale or linetype, not colour
我有一个散点图,用 2 级因子分割得更平滑;我需要将所有内容都保存在一张图表上,但不能使用颜色。
所以我希望因子的两个级别不同 (1) 灰度(例如,深灰色与黑色)(2) 或线型(例如,虚线与实线)。
谢谢,
数据:
ppn, condition,pns, apav
1,inconsistenr,3.92,2.00
2,inconsistent,2.50,3.75
3,consistent, 4.08,2.25
4,inconsistent,2.67,5.50
5,consistent,3.58,5.00 (...)
代码:
library(ggplot2)
scatter <- ggplot(PINC3, aes(pns, apav, colour = condition))
scatter + geom_point() + geom_smooth(method = "lm", alpha = .15)
您可以使用 ggplot2 中的 RColorBrewer 调色板将颜色设置为灰度。
library(ggplot2)
scatter <- ggplot(PINC3, aes(pns, apav, colour = condition))
scatter + geom_point() + geom_smooth(method = "lm", alpha = .15) +
scale_color_brewer(palette = "Greys)
根据 condition
设置线型使用 linetype
作为美学,它应该与 geom_smooth
:
一起使用
scatter <- ggplot(PINC3, aes(pns, apav, linetype = condition))
scatter +
geom_point(aes(shape = condition)) +
geom_smooth(method = "lm", alpha = .15)
我有一个散点图,用 2 级因子分割得更平滑;我需要将所有内容都保存在一张图表上,但不能使用颜色。
所以我希望因子的两个级别不同 (1) 灰度(例如,深灰色与黑色)(2) 或线型(例如,虚线与实线)。
谢谢,
数据:
ppn, condition,pns, apav
1,inconsistenr,3.92,2.00
2,inconsistent,2.50,3.75
3,consistent, 4.08,2.25
4,inconsistent,2.67,5.50
5,consistent,3.58,5.00 (...)
代码:
library(ggplot2)
scatter <- ggplot(PINC3, aes(pns, apav, colour = condition))
scatter + geom_point() + geom_smooth(method = "lm", alpha = .15)
您可以使用 ggplot2 中的 RColorBrewer 调色板将颜色设置为灰度。
library(ggplot2)
scatter <- ggplot(PINC3, aes(pns, apav, colour = condition))
scatter + geom_point() + geom_smooth(method = "lm", alpha = .15) +
scale_color_brewer(palette = "Greys)
根据 condition
设置线型使用 linetype
作为美学,它应该与 geom_smooth
:
scatter <- ggplot(PINC3, aes(pns, apav, linetype = condition))
scatter +
geom_point(aes(shape = condition)) +
geom_smooth(method = "lm", alpha = .15)