如何更改X轴比例

时间:2019-06-26 15:19:12

标签: r

enter image description here我已经生成了1000组用于Poisson分布的随机数据,并将所有数据绘制到一个概率分布图中。我想将x轴比例单位更改为2,例如0、2、4、6、8、10...。我已经设置了x轴的最大值和最小值,但没有显示我期望

set.seed(124)

Sample1000 <- replicate(1000, matrix(data=rpois(100, lambda = 3),ncol = 1), simplify = TRUE)
Graph1000 <- gather(as.data.frame(Sample1000))
View(Sample1000)
colMeans(Sample1000)
apply(Sample1000, 2, var)

ggplot(Graph1000, aes(x = value)) +
  geom_density(aes(group = key)) +
  labs(x = "y", y = "P(y)", title = "Probability density function for 1000 sample") +
  theme_classic() +
  theme(plot.title = element_text(hjust = 0.5)) +
  scale_x_continuous(expand = c(0,0), limits = c(0,14))  +
  scale_y_continuous(expand = c(0,0))

1 个答案:

答案 0 :(得分:0)

您可以在breaks上设置scale_x_continuous()
这是产生绘图的代码:

ggplot(Graph1000, aes(x = value)) +
  geom_density(aes(group = key)) +
  labs(x = "y", y = "P(y)", title = "Probability density function for 1000 sample") +
  theme_classic() +
  theme(plot.title = element_text(hjust = 0.5)) +
  #Set breaks on x axis
  scale_x_continuous(breaks = seq(from = 0,to = 14,by = 2), limits = c(0,14))  +
  scale_y_continuous(expand = c(0,0))