Character Values ​​on the Continuous Axis in R ggplot2

Is there a way to include character values ​​for axes when building continuous data with ggplot2? I received censorship data such as:

xy Freq 1 -3 16 3 2 -2 12 4 3 0 10 6 4 2 7 7 5 2 4 3 

The last row of data is censored. I draw this using the code below to create the following graph:

 a1 = data.frame(x=c(-3,-2,0,2,2), y=c(16,12,10,7,4), Freq=c(3,4,6,7,3)) fit = ggplot(a1, aes(x,y)) + geom_text(aes(label=Freq), size=5)+ theme_bw() + scale_x_continuous(breaks = seq(min(a1$x)-1,max(a1$x)+1,by=1), labels = seq(min(a1$x)-1,max(a1$x)+1,by=1), limits = c(min(a1$x)-1,max(a1$x)+1))+ scale_y_continuous(breaks = seq(min(a1$y),max(a1$y),by=2)) 

enter image description here

The 3 points in (2,4) are censored. I would like them to be built on one unit on the right with the corresponding label xaxis '> = 2' instead of 3. Any ideas if this is possible?

+4
source share
1 answer

It is quite possible. I hacked data so 2,4 it 3,4 . Then I changed your tags, which can be whatever you want, as long as they have the same length, like breaks.

 ggplot(a1, aes(x,y)) + geom_text(aes(label=Freq), size=5)+ theme_bw() + scale_x_continuous(breaks = seq(min(a1$x)-1,max(a1$x),by=1), labels = c(seq(min(a1$x)-1,max(a1$x)-1,by=1), ">=2"), limits = c(min(a1$x)-1,max(a1$x)))+ scale_y_continuous(breaks = seq(min(a1$y),max(a1$y),by=2)) 

enter image description here

+4
source

All Articles