Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R + OpenStreetMap + ggplot2 + change tick marks

I'm trying to manipulate the axis tick marks in a UK map

map = openmap(upperLeft = c(60,-11), 
              lowerRight = c(49.5,3), type="mapquest-aerial")
map2 <- openproj(map)
autoplot(map2) +
  xlab("Longitude") + ylab("Latitude")

enter image description here I tried adding something like this:

  scale_x_continuous(breaks=seq(-10,2,2), labels=paste(c(rev(seq(0,10,2)),2),c(rep("°W",5),"°","°E"),sep=""))

I will get an error message: Scale for 'x' is already present. Adding another scale for 'x', which will replace the existing scale.

(probably because the scale is set in the map object) and although it does append the labels, the axis get shifted and a gap is created left and right of the plot: enter image description here Does anyone know how I can get rid of this grey space???

R version 3.0.0 Platform: i386-w64-mingw32/i386 (32-bit)

like image 558
Joanne Demmler Avatar asked Oct 24 '25 03:10

Joanne Demmler


1 Answers

You got warning about the already present x axis because function autoplot.OpenStreetMap() (actually called by autoplot()) already has scale_x_continuous() defined. So you are making new x axis.

You can remove gray area just by adding argument expand=c(0,0) to your scale function. This argument is included in scale function that autoplot() uses.

 +scale_x_continuous(breaks=seq(-10,2,2), labels=paste(c(rev(seq(0,10,2)),2),
                                c(rep("°W",5),"°","°E"),sep=""),expand=c(0,0))
like image 91
Didzis Elferts Avatar answered Oct 26 '25 17:10

Didzis Elferts



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!