Alexander - 6 months ago 77

R Question

I want to make usual geom_point plot using ggplot. But some of x values are repeated and I want to repeat them again in the x axis. So I tried

`scale_x_discrete`

Here is my example

`x = c(seq(1,4),seq(2,4))`

y= (seq(1,7))

ex=rep(c("ex1","ex2"),c(4,3))

df <- data.frame(x,y,ex)

x y ex

1 1 1 ex1

2 2 2 ex1

3 3 3 ex1

4 4 4 ex1

5 2 5 ex2

6 3 6 ex2

7 4 7 ex2

ggplot(df, aes(x=factor(x),y=y)) +

geom_point(size=4) +

scale_x_discrete(limits=c(seq(1,4),seq(2,4)))

with discrete x repeat values, the repeated x axis values is not shown. How can repeat

`2,3,4`

`1,2,3,4`

Thanks

Answer