我想在其中一个地块上添加图例,但是我有不同的审美观,并且我从未创建过图例,因此我很难确定如何构建图例。
我的审美观之一是填充代码,我将其手动添加为矢量。另一种美学是我在geom_vline中添加的垂直线。
从下面的图形中,我想添加到图例中的三个特征:1)颜色为深蓝色的条,2)颜色为浅蓝色的条,以及3)垂直线。
有人对我有建议如何有效地编码吗?
#df
df <- data.frame(Time_Diff <- runif(1000, 0, 200))
# Show median, IQR range and outliers
colors <- c(rep("blue",3), rep("paleturquoise2",38))
bp_overall <- ggplot(data = df, aes(Time_Diff))
bp_overall +
geom_histogram(binwidth = 5, fill = colors) + #create histogram
ggtitle("Time Difference") +
xlab("Time in Days") +
ylab("Amount") +
geom_vline(xintercept = 3, linetype = "twodash", size = 1, colour= "darkblue") + #show median
scale_x_continuous(breaks = seq(0, 202, 10)) +
theme_light() +
theme(panel.grid.minor = element_blank(),
panel.border = element_blank(), #remove all border …Run Code Online (Sandbox Code Playgroud)