【发布时间】:2018-10-19 07:51:21
【问题描述】:
我正在编辑一个情节。我在轴格式方面犯了错误,想修复它们。但是,如果我在错误的代码之后编写正确的代码,则新轴将添加到现有轴的顶部,而不是替换它们。有没有更好的方法来修改轴而不从头开始绘制绘图?
这是代码:
library("sp")
#Prepare data
data("meuse.riv")
meuse.lst <- list(Polygons(list(Polygon(meuse.riv)),"meuse.riv"))
meuse.sr <- SpatialPolygons(meuse.lst)
#Create the plot
plot(meuse.sr, axes = F)
axis(1, at = c(178000 + 0:2 * 2000), cex.axis = 0.7)
#Code with a mistake: I need 3 stretches insted of 2
axis(1, at = c(178000 + 0:3 * 2000), cex.axis = 0.7)
#Right code but new axis is added to the old one; it can be seen because old part looks bolder
axis(2, at = c(326000 + 0:3 * 4000))
#Code with a mistake: I need smaller font (cex.axis = 0.7)
axis(2, at = c(326000 + 0:3 * 4000), cex.axis = 0.7)
#Right code but new labels are laid over the old ones. They are not readable.
【问题讨论】:
-
使用
ggplot并将绘图保存到一个对象中。然后,您可以在之后添加内容或更改布局,而无需再次计算绘图。