【发布时间】:2020-04-15 09:25:16
【问题描述】:
我使用 ggplot2 创建了一个折线图,并且颜色图例是连续的。我想将其更改为离散的彩色线条。我有以下代码:
library(ggplot2)
ggplot(df, aes(L)) +
geom_line(aes(y = Updated, colour = S, group = S, linetype = "Updated")) +
geom_line(aes(y = Current, colour = S, group = S, linetype = "Current")) +
scale_color_gradient() +
labs(x = element_text("Span Length (ft)"), y = element_blank(),
title = "Moment Live Load Distribution Factors \n Exterior Girder - Multi Lane",
linetype = "AASHTO", color = "Spacing (ft)") +
scale_linetype_manual(values = c(1, 3),
labels = c("Updated", "Current")) +
theme_classic() +
theme(plot.title = element_text(hjust = 0.5, margin = margin(0,0,20,0), size = 18),
legend.position="top",
legend.box.background = element_rect(colour = "black", size = 0.5),
legend.box.margin = margin(0,0,0,0), legend.background = element_blank())
我想将图例的连续部分转换为与图例其余部分宽度相同的彩色线条。谢谢!
【问题讨论】: