【发布时间】:2021-01-17 21:44:27
【问题描述】:
我想为 ggplot 中的一行更改size、linetype、color 等。
这是一个最小的可重现示例:
library(tidyverse)
# Data in wide format
df_wide <- data.frame(
Horizons = seq(1,10,1),
Country1 = c(2.5, 2.3, 2.2, 2.2, 2.1, 2.0, 1.7, 1.8, 1.7, 1.6),
Country2 = c(3.5, 3.3, 3.2, 3.2, 3.1, 3.0, 3.7, 3.8, 3.7, 3.6),
Country3 = c(1.5, 1.3, 1.2, 1.2, 1.1, 1.0, 0.7, 0.8, 0.7, 0.6)
)
# Convert to long format
df_long <- df_wide %>%
gather(key = "variable", value = "value", -Horizons)
# Plot the lines
plotstov <- ggplot(df_long, aes(x = Horizons, y = value)) +
geom_line(aes(colour = variable, group = variable))+
theme_bw()
如何更改Country1 的size、linetype、color,而不必绘制每一行
分别,例如:geom_line(aes( y = Country1...)) + geom_line(aes(y = Country2...)),因此突出显示Country1?
提前非常感谢!
【问题讨论】:
-
你可以应用相同的逻辑看到here