我怎样才能使这些样条线的颜色变暗?
How can I darken the colour of these splines?
随着数据点数量的增加,样条线在背投下变得不可见。
我怎样才能使样条线的颜色变暗?
或者其他方法来解决这个可见性问题?
library(dplyr)
library(ggplot2)
library(mgcv)
# Summer
Summer <- mgcv::gamSim(eg=5,n=10000,dist="normal",scale=0.6,verbose=TRUE) %>%
mutate(x = x2 * 20) %>%
rename("Season" = x0) %>%
mutate(Season = ifelse(Season == "1", "Summer", Season)) %>%
filter(.,Season == "Summer") %>%
select(y, x, Season)
# Winter
Winter <- mgcv::gamSim(eg=5,n=10000,dist="normal",scale=1.0,verbose=TRUE) %>%
mutate(x = x1 * 20) %>%
rename("Season" = x0) %>%
mutate(Season = ifelse(Season == "3", "Winter", Season)) %>%
filter(.,Season == "Winter") %>%
select(y, x, Season)
# Bind
DF <- rbind(Summer, Winter)
# Plot
Plot <- DF %>%
ggplot(., aes(x = x, y = y, colour = Season)) +
geom_jitter() +
geom_point(shape=21, alpha = 0.5, size=0.05) +
geom_smooth(method = "gam", formula = y ~ s(x, bs = "cs", k = 10), lwd = 1.6)
Plot
- 您的
geom_jitter()
正在创建全尺寸和完全不透明的点;相反,将 position = "jitter"
添加到 geom_point()
(我假设你真的不想要 both 抖动点和原始位置的点?)
- 我在你的
geom_point()
中调整了 alpha
和 size
,但你可能想要更多地使用它们(即,随着样本量的增加,减小大小和不透明度) .如果您的数据集变得非常大,您可以尝试使用 geom_hexbin()
。
- 我发现通过
theme_bw()
(甚至 theme_classic()
)将背景更改为白色可以更轻松地查看背景中的值。
你不能使拟合线更暗(除非你想切换到 scale_color_manual(values = c("red", "blue"))
之类的东西),但如果你想更清楚地看到置信度带,你可以增加 alpha
and/or 为它们设置 fill
颜色。
Plot <- DF %>%
ggplot(., aes(x = x, y = y, colour = Season)) +
geom_point(shape=21, alpha = 0.7, size=0.5, position = "jitter") +
geom_smooth(method = "gam", formula = y ~ s(x, bs = "cs", k = 10), lwd = 1.6) +
theme_bw()
如果您希望线条突出于点,那么我会将 alpha
调整为 geom_jitter
。部分问题是您在抖动上绘制点。我不认为你需要这两个(除非我遗漏了什么)。
library(ggplot2)
Plot <- DF %>%
ggplot(., aes(x = x, y = y, colour = Season)) +
geom_jitter(alpha = 0.2) +
geom_smooth(method = "gam", formula = y ~ s(x, bs = "cs", k = 10), lwd = 1.6)
Plot
随着数据点数量的增加,样条线在背投下变得不可见。 我怎样才能使样条线的颜色变暗? 或者其他方法来解决这个可见性问题?
library(dplyr)
library(ggplot2)
library(mgcv)
# Summer
Summer <- mgcv::gamSim(eg=5,n=10000,dist="normal",scale=0.6,verbose=TRUE) %>%
mutate(x = x2 * 20) %>%
rename("Season" = x0) %>%
mutate(Season = ifelse(Season == "1", "Summer", Season)) %>%
filter(.,Season == "Summer") %>%
select(y, x, Season)
# Winter
Winter <- mgcv::gamSim(eg=5,n=10000,dist="normal",scale=1.0,verbose=TRUE) %>%
mutate(x = x1 * 20) %>%
rename("Season" = x0) %>%
mutate(Season = ifelse(Season == "3", "Winter", Season)) %>%
filter(.,Season == "Winter") %>%
select(y, x, Season)
# Bind
DF <- rbind(Summer, Winter)
# Plot
Plot <- DF %>%
ggplot(., aes(x = x, y = y, colour = Season)) +
geom_jitter() +
geom_point(shape=21, alpha = 0.5, size=0.05) +
geom_smooth(method = "gam", formula = y ~ s(x, bs = "cs", k = 10), lwd = 1.6)
Plot
- 您的
geom_jitter()
正在创建全尺寸和完全不透明的点;相反,将position = "jitter"
添加到geom_point()
(我假设你真的不想要 both 抖动点和原始位置的点?) - 我在你的
geom_point()
中调整了alpha
和size
,但你可能想要更多地使用它们(即,随着样本量的增加,减小大小和不透明度) .如果您的数据集变得非常大,您可以尝试使用geom_hexbin()
。 - 我发现通过
theme_bw()
(甚至theme_classic()
)将背景更改为白色可以更轻松地查看背景中的值。
你不能使拟合线更暗(除非你想切换到 scale_color_manual(values = c("red", "blue"))
之类的东西),但如果你想更清楚地看到置信度带,你可以增加 alpha
and/or 为它们设置 fill
颜色。
Plot <- DF %>%
ggplot(., aes(x = x, y = y, colour = Season)) +
geom_point(shape=21, alpha = 0.7, size=0.5, position = "jitter") +
geom_smooth(method = "gam", formula = y ~ s(x, bs = "cs", k = 10), lwd = 1.6) +
theme_bw()
如果您希望线条突出于点,那么我会将 alpha
调整为 geom_jitter
。部分问题是您在抖动上绘制点。我不认为你需要这两个(除非我遗漏了什么)。
library(ggplot2)
Plot <- DF %>%
ggplot(., aes(x = x, y = y, colour = Season)) +
geom_jitter(alpha = 0.2) +
geom_smooth(method = "gam", formula = y ~ s(x, bs = "cs", k = 10), lwd = 1.6)
Plot