如何改变 中线条边框的颜色geom_smooth()
?
library(ggplot2)
mtcars$cyl <- as.factor(mtcars$cyl)
ggplot(mtcars, aes(x=wt, y=mpg, color=cyl, shape=cyl)) +
geom_point() +
geom_smooth(method=lm)
Run Code Online (Sandbox Code Playgroud)
它应该看起来像这样:
感谢您的时间!
我有这个情节:
library(ggplot2)
ggplot(iris,
aes(
x = Petal.Length,
y = Petal.Width,
color = Species,
linetype = Species,
shape = Species
)) +
geom_count(alpha = 0.20) +
geom_smooth(method = "lm", se = FALSE) +
labs(
color = "Species (Line)",
linetype = "Species (Line)",
shape = "Species (Points)"
) +
guides(
size = "none"
)
#> `geom_smooth()` using formula = 'y ~ x'
Run Code Online (Sandbox Code Playgroud)
创建于 2023 年 11 月 2 日,使用reprex v2.0.2
我正在尝试格式化图例,以便有一个具有点形状(也按颜色)的图例和一个单独的线型图例(也按颜色)。
我实际上得到的是一个仅用于形状(无颜色)的图例和一个具有彩色点的线型图例。我已经尝试了我能想到的图例标签的每一次迭代,但都无济于事。
问题:保持其他一切不变,我怎样才能摆脱物种(线)图例中的那些点?以及如何为形状添加颜色?
我想我一定是误解line =
了 中的论点theme()
。根据 中的文档?theme
,line =
应该会影响图中的所有线元素。然而,改变颜色没有任何作用,而改变大小却起作用。
library(ggplot2)
ggplot(iris, aes(x = Sepal.Width, Petal.Length)) +
geom_point() +
geom_smooth() +
theme(line = element_line(color = "green", size = 5))
#> `geom_smooth()` using method = 'loess' and formula 'y ~ x'
Run Code Online (Sandbox Code Playgroud)
由reprex 包于 2022 年 8 月 15 日创建(v2.0.1)
我的问题有两个:
为什么更改颜色不会影响图中的任何线条?
为什么更改尺寸不会影响 中的线条元素geom_smooth()
?
编辑:请参阅@Gregor Thomas 的答案以获取第 2 部分的答案。