简体   繁体   中英

How to change the x-axis scale

enter image description here I have generate 1000 set of random data for Poisson Distribution and plot all the data into a probability distribution graph. I would like to change the x-axis scale as 2 per unit like 0,2,4,6,8,10....I have set the max and min value of x-axis but it didn't show what I expect

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))

You can set the breaks on scale_x_continuous() .
Here is the code that produce your plot:

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))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM