简体   繁体   中英

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

在此输入图像描述 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: 在此输入图像描述 Does anyone know how I can get rid of this grey space???

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

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

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