我知道之前已经问过这个问题,但解决方案对我来说似乎并不适用.
我想要做的是用不同颜色的直方图表示我的中位数,平均值,上下分位数,然后在图中添加一个图例.这是我到目前为止,我试图使用scale_color_manual
并scale_color_identity
给我一个传奇.似乎没有什么工作.
quantile_1 <- quantile(sf$Unit.Sales, prob = 0.25)
quantile_2 <- quantile(sf$Unit.Sales, prob = 0.75)
ggplot(aes(x = Unit.Sales), data = sf) +
geom_histogram(color = 'black', fill = NA) +
geom_vline(aes(xintercept=median(Unit.Sales)),
color="blue", linetype="dashed", size=1) +
geom_vline(aes(xintercept=mean(Unit.Sales)),
color="red", linetype="dashed", size=1) +
geom_vline(aes(xintercept=quantile_1), color="yellow", linetype="dashed", size=1)
Run Code Online (Sandbox Code Playgroud)
我有一张桌子:
id time
1 1
1 2
1 5
2 3
2 2
2 7
3 8
3 3
3 14
Run Code Online (Sandbox Code Playgroud)
我想将其转换为:
id first last
1 1 5
2 3 7
3 8 14
Run Code Online (Sandbox Code Playgroud)
请帮忙!