gpt4 book ai didi

r - 如何在R中移动绘图

转载 作者:行者123 更新时间:2023-12-01 13:43:30 25 4
gpt4 key购买 nike

我想绘制一个 shapefile 并在旁边添加一个颜色条。我通过以下代码添加了颜色条。

  image.plot(legend.only = TRUE, zlim = c(0, 1000),
col = colorbar, nlevel = 4, horizontal = FALSE, legend.shrink = 0.7)

我的问题如下图,colorbar与plot交互。

enter image description here

然后我找到了一些将颜色条移动

的解决方案
image.plot(legend.only = TRUE, zlim = c(0, 1000),
col = colorbar, nlevel = 4, horizontal = FALSE, legend.shrink = 0.7, smallplot = c(0.95, 0.99, 0.3, 0.7))

但是现在变成这样了,现在连数字都看不到了。

enter image description here

有什么方法可以将图向左移动一点,以便为颜色条留出一些位置?或者有什么方法可以扩展绘图面板来放置颜色条?谢谢。

最佳答案

调整图像和图例的 oma。这是一个例子:

数据:

structure(c(1.75267599319517, 1.94305075507445, -0.156487381738027, 
0.445640426661944, 1.47524414033855, 1.02750392394893, -1.22677726427257,
0.328939164881444, 1.8373305915836, -2.60705394935169, -0.176565075649185,
0.686525129060304, -0.270880825694669, 0.228427158100646, 0.296087431746941,
0.159733127698645, -0.335874862599458, -1.48189689355783, 2.28164829999553,
-0.221602702990901, -1.19118638639445, -0.669176494493408, 0.146646167689706,
-0.356170596317782, -1.25338279788711, 1.590956130167, -0.0859783795499388,
1.28699804800428, 0.673030469365775, 1.50431821599456, -0.0415374929905405,
-1.66641620237076, -0.466513627830826, 0.224700229437091, -0.0935518596695337,
1.77372649149139, -0.324986645432598, -0.717452050358237, -0.652792543676794,
-0.63363234302696, -1.33373586598015, 0.287736774848359, -2.0047033043693,
-0.169110483354588, -1.00746374158438, 1.09791123137282, 0.835200025940813,
1.49766948516664, -0.372579472535408, 0.0928212636896341, -0.596541205386888,
-2.08914364716957, -0.0329161555494402, 0.0469126764319172, 0.901591475473942,
-1.81735802943062, 0.0116636902497983, -0.857668758902046, -0.0123288459943967,
-2.06908827360805, -2.04305175171055, 0.230800348099395, -0.548843960606738,
0.42156183975044, 0.0374174028221, -0.564919467814281, -1.48228025377204,
-0.687727667103207, 1.28230405559294, 0.680295500103408, -2.14368865783057,
0.259858393651711, -1.01732304373518, -0.0188730011118445, -0.386878321355593,
-0.810280425180489, 0.706333208066621, 0.783769913289453, -0.245972056614985,
0.216018643466252, -0.721116233056827, 1.4782390752923, -2.08847116325789,
0.924181052813952, 0.740754382565328, 0.537848528023596, -1.40878671892895,
-0.0870042863455953, 0.797988334415009, -0.601329461472177, -1.15426452376043,
1.28814038900589, -0.997765393519507, 1.09387671511455, 0.599442343976457,
0.323252016862286, -0.338054796460218, 1.60358639606103, -0.836761687404309,
0.224602950250348, 0.457867653133552, 0.111812983058114, -1.94611223307409,
0.816617488615419, 0.803506493408523, -3.27213559068651, 0.914990262538904,
1.04878880717756, 1.02930117080295, -0.780637711297084, -1.63107614827176,
-0.780474130437691, 1.75029718369322, 0.896818981075001, -0.388043322063959,
-0.472369396803673, 0.949964242662063, -0.665981283816353, 1.14546357500757,
-0.149619678444026, 1.31405614654295, -0.916785592776755, 0.595768148350207,
0.554906368528589, -0.64216913243052, -0.141294344542147, -1.10328974307499,
-0.0523192529246229, -0.16760238083543, -2.21744159323307, 0.293362942177156,
-0.198123321190054, -1.27367916442953, 1.3475805394527, 0.379260832421235,
-1.21921905754775, -0.715980480102964, -0.719626343992431, 1.1512160588389,
-0.84503724263784, -1.79029200798331, 1.00839282965634, 1.8043734147227,
-1.0819177220181, -0.200947360793273, -0.30353527334045, 0.444037029616591,
-0.478592762144137, 0.834712578703853, -0.119438685285821), .Dim = c(10L, 15L))

为右侧边距设置 4 行:

par(oma=c(0,0,0,4))
image(data)

在绘制图例之前重置右侧的外边距:

par(oma=c( 0,0,0,1))
image.plot( legend.only=TRUE, zlim=c(-4,4))

enter image description here

关于r - 如何在R中移动绘图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37825539/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com