我用直方图覆盖散点图,然后使用xlim()
设置x轴。但似乎xlim()
删除了直方图的1和10,但对散点图没有影响。
library(ggplot2)
library(plotly)
(d <- data.frame(key = 1:10, value = 1:10))
# xlim() seems to not include 1 and 10 for the histogram
ggplot(data = d, aes(x = value)) +
geom_histogram(binwidth = 1) +
geom_point(data = d, aes(x = key, y = value)) +
xlim(1, 10)
此处使用的ggplot2版本为2.2.1