如何更改geom_point中的颜色或ggplot中的线

一世

我有这样的数据

data<- structure(list(sample = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("A", 
"B"), class = "factor"), y = c(0.99999652, 0.99626012, 0.94070452, 
0.37332406, 0.57810894, 0.37673758, 0.22784684, 0.35358141, 0.21253558, 
0.17715703, 0.99999652, 0.86403956, 0.64054516, 0.18448824, 0.40362691, 
0.10791682, 0.06985696, 0.07384465, 0.0433271, 0.02875159), time = c(100L, 
150L, 170L, 180L, 190L, 220L, 260L, 270L, 300L, 375L, 100L, 150L, 
170L, 180L, 190L, 220L, 260L, 270L, 300L, 375L), x = c(0.9999965, 
0.9981008, 0.9940164, 1.0842966, 0.9412978, 1.0627907, 0.9135079, 
1.1982235, 0.9194105, 0.9361713, 0.9999965, 1.0494051, 0.9526752, 
1.1594711, 0.9827104, 1.0223711, 1.1419197, 1.0328598, 0.6015229, 
0.3745817)), .Names = c("sample", "y", "time", "x"), class = "data.frame", row.names = c(NA, 
-20L))

我有兴趣将其绘制成黑色和红色等服装色

我可以用两种随机的不同颜色绘制它,但问题是

ggplot() + 
geom_point(data = data, aes(x = time, y = y, color = sample),size=4)

如果我想将第一个(A)分配给黑色,将(B)分配给红色。我怎样才能做到这一点?

迈克·H

您可以使用scale_color_manual

ggplot() + 
  geom_point(data = data, aes(x = time, y = y, color = sample),size=4) +
  scale_color_manual(values = c("A" = "black", "B" = "red"))

在此处输入图片说明


根据OP的评论,获得与您可以做的点相同颜色的线条:

ggplot(data = data, aes(x = time, y = y, color = sample)) + 
  geom_point(size=4) + 
  geom_line(aes(group = sample)) + 
  scale_color_manual(values = c("A" = "black", "B" = "red"))

在此处输入图片说明

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何用点的颜色填充geom_point图例中的框,而不仅仅是增加它们的大小?

ggplot geom_point(),其颜色基于特定的离散值

ggplot2 2.0.0中的geom_point边界

在R中,ggplot geom_point()的颜色基于特定的离散值-第2部分

更改ggplot2中geom_point()的默认点大小?

从图例中删除ggplot2的geom_point图标

如何在R中为我的数据构建ggplot geom_point()?

如何强制geom_point在R中显示比例大小?

如何在ggplot2中获取堆叠的geom_bar和geom_point的通用图例?

ggplot中的自定义形状(geom_point)

ggplot图例(geom_point)中的空白条目?

为ggplot在geom_point上订购颜色

为ggplot2中的负值和正值在geom_point中设置不同的颜色

在geom_point中使用cut时如何在ggplot中添加椭圆

R中的Geom_text()-如何更改geom_point中特定点的标签位置

ggplot:geom_point中的颜色,填充和大小

如何更改ggplot2的geom_point中缺失值的颜色?

增加ggplot geom_point中的最小点大小

geom_point {ggplot2}中的alpha值

如何更改代表ggplot中变量范围的线的颜色?

R ggplot2-如何为两个geom_point指定不同的颜色

ggplot2 中的振幅线 + geom_point

如何更改 geom_point 外观?

无论如何要更改 R (geom_point) 中 ggplot 中值的大小?

有没有办法在 R 中更改 ggplot2 (geom_point) 中的大小值范围?

如何根据python中的条件添加geom_point层

根据列中的值更改 geom_point 的大小

ggplot,基于变量的geom_point颜色

如何减少ggplot中geom_point()之间的相对距离