How to precisely set the axis position [duplicate]

别等时光非礼了梦想. 提交于 2020-01-06 06:10:51

问题


I need to crop a plot so that the axes are precisely set on a known x and y line. coord_cartesian does not behave in this way (see below). So for instance, in the image below I would like the axis to sit directly on the 30 or 40 marks. Any ideas would be greatly appreciated as this is prooving a difficult thing to google!

Edit: This was marked as a duplicate and the question may be a duplicate but the answer I got is different from those in the marked duplicates, and in my view simpler and better.

library(ggplot2)
library(cowplot)
library (rgdal)
library (rgeos)
library(maptools)

poly <- readShapePoly("Countries_WGS84/Countries_WGS84.shp")
polygon <- fortify(poly)

map <- ggplot() + 
  geom_polygon(data=polygon, aes(long, lat, group = group)) +
  coord_cartesian(xlim=c(2, 12),c(30,40)) 

save_plot("map.png",map ,base_asp = 1, base_height = 10)

来源:https://stackoverflow.com/questions/59079147/how-to-precisely-set-the-axis-position

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!