R:使用ggplot指定折线图中的特殊点
R: Specify special points in line graph using ggplot
我想使用 ggplot 在折线图上指定两个点,如下所示。我该怎么做?
library(ggplot2)
ggplot(mtcars, aes(wt, mpg)) +
geom_line() +
geom_segment(aes(x = 2, y = 0, xend = 2, yend = 25), linetype=2) +
geom_segment(aes(x = 0, y = 25, xend = 2, yend = 25), linetype=2) +
geom_point(data=data.frame(lat = c(25), long = c(2)),aes(long,lat),colour="blue",size=4) +
geom_segment(aes(x = 1, y = 0, xend = 1, yend = 20), linetype=2) +
geom_segment(aes(x = 0, y = 20, xend = 1, yend = 20), linetype=2) +
geom_point(data=data.frame(lat = c(20), long = c(1)),aes(long,lat),colour="blue",size=4)
你用 geom_segment and/or geom_point.
查看here了解如何更改轴标签/刻度。
编辑:为了第二点,我编辑了我的 post。
我想使用 ggplot 在折线图上指定两个点,如下所示。我该怎么做?
library(ggplot2)
ggplot(mtcars, aes(wt, mpg)) +
geom_line() +
geom_segment(aes(x = 2, y = 0, xend = 2, yend = 25), linetype=2) +
geom_segment(aes(x = 0, y = 25, xend = 2, yend = 25), linetype=2) +
geom_point(data=data.frame(lat = c(25), long = c(2)),aes(long,lat),colour="blue",size=4) +
geom_segment(aes(x = 1, y = 0, xend = 1, yend = 20), linetype=2) +
geom_segment(aes(x = 0, y = 20, xend = 1, yend = 20), linetype=2) +
geom_point(data=data.frame(lat = c(20), long = c(1)),aes(long,lat),colour="blue",size=4)
你用 geom_segment and/or geom_point.
查看here了解如何更改轴标签/刻度。
编辑:为了第二点,我编辑了我的 post。