Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete ticks between breaks in ggplot

Tags:

r

ggplot2

I'd like to create a line graph with irregular break intervals on the x-axis. When I define the breaks as in the code example, I get additional unlabeled breaks, which always seem to be exactly in the middle of two defined breaks and thus are unregular too (see image in link).

test_frame <- data.frame("v1"=1:3,"v2"=3:1)

library(ggplot2)
ggplot(data = test_frame, aes(x=v1, y=v2, group=1))+geom_line()+
scale_x_continuous(breaks = c(2.74,2.43,1.19))

Graph with additional breaks:

Graph with additional breaks

Is there any way to get rid of these vertical lines, so that there are only lines at the defined break position? I'd be grateful for any suggestions.

like image 735
agermanguy Avatar asked Sep 09 '26 23:09

agermanguy


2 Answers

Set minor_breaks = NULL:

scale_x_continuous(breaks = c(2.74,2.43,1.19), minor_breaks = NULL)

enter image description here

like image 170
Stéphane Laurent Avatar answered Sep 12 '26 07:09

Stéphane Laurent


ggplot(data = test_frame, aes(x = v1, y = v2, group = 1)) +
  geom_line() +
  scale_x_continuous(breaks = c(2.74, 2.43, 1.19)) +
  theme(panel.grid.minor = element_blank()) # or panel.grid.minor.x to keep horizontal lines

enter image description here

like image 41
sindri_baldur Avatar answered Sep 12 '26 09:09

sindri_baldur



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!