R 图例中的值被缩短为 Ne+n 形式
我们正在尝试使用 R 打印一些芬兰林业地图。地图绘制得很好,但图例中的一些数字并未完整显示,而是以 3e+06 的格式显示。
当图例中的行大小太长时,似乎会发生这种情况。对于某些用户来说这可能是个问题。
我一直在寻找如何更改它以显示完整的数字。任何如何解决这个问题的想法将不胜感激,因为我已经为此奋斗了好几天。来源如下。
library(maptools)
library(RColorBrewer)
library(classInt)
Sys.setlocale(category = 'LC_ALL', locale = 'fi_FI@euro')
png(file="tupatmp/950fi_4.png", height=600, width=600, res=100)
basemap <- readShapePoly("shp/metsakeskus.shp",IDvar="mknro_1")
xx <- basemap[basemap$att.data$mknro_1 %in% c(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14)]
csv <- read.csv("tupatmp/950fi.csv")
plotvar <- csv$k_4
nclr <- 8
plotclr <- brewer.pal(nclr,"RdYlGn")
options(digits = 10)
class <- classIntervals(plotvar,
nclr,
style="fixed",
fixedBreaks=c(0,5000,10000,15000,20000,250000,3000000,3500000,40000000))
colcode <- findColours(class, plotclr,digits = getOption(digits))
plot(xx,col=colcode)
par(family="sans")
par(mgp = c(0,1,0))
title(main = "Nettotulojen nykyarvon maksimointi 5% korkokannalla 2037
Ahvenanmaa, Lounais-Suomi, Häme-Uusimaa, Kaakkois-Suomi, Pirkanmaa, Etelä-Savo, Etelä-Pohjanmaa, Keski-Suomi, Pohjois-Savo, Pohjois-Karjala, Kainuu, Pohjois-Pohjanmaa, Lappi, Rannikko (pohjanmaa), Rannikko (etelärannikko)",
sub = "Kantohinta-arvo Käytönrajoitus: Puuntuotannon ulkopuolella",
font.main=2,cex.main=0.9,cex.sub=0.9)
legend(2730000,7315000,
title="1000eur",legend=names(attr(colcode,"table")),
fill=attr(colcode,"palette"),
border="black", cex=0.8,bty="o", xpd="FALSE")
dev.off()
We are trying to print some Finnish forestry maps using R. The map is drawn nicely but some of numbers in the legends are not shown in their full length, but in the format 3e+06.
This seem to happen when the size of a row in the legend is too long. This might be problem for some users.
I have been looking for how to change it to show the full numbers. Any ideas how to fix this will be appreciated as I have been battling with this for several days. Source below.
library(maptools)
library(RColorBrewer)
library(classInt)
Sys.setlocale(category = 'LC_ALL', locale = 'fi_FI@euro')
png(file="tupatmp/950fi_4.png", height=600, width=600, res=100)
basemap <- readShapePoly("shp/metsakeskus.shp",IDvar="mknro_1")
xx <- basemap[basemap$att.data$mknro_1 %in% c(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14)]
csv <- read.csv("tupatmp/950fi.csv")
plotvar <- csv$k_4
nclr <- 8
plotclr <- brewer.pal(nclr,"RdYlGn")
options(digits = 10)
class <- classIntervals(plotvar,
nclr,
style="fixed",
fixedBreaks=c(0,5000,10000,15000,20000,250000,3000000,3500000,40000000))
colcode <- findColours(class, plotclr,digits = getOption(digits))
plot(xx,col=colcode)
par(family="sans")
par(mgp = c(0,1,0))
title(main = "Nettotulojen nykyarvon maksimointi 5% korkokannalla 2037
Ahvenanmaa, Lounais-Suomi, Häme-Uusimaa, Kaakkois-Suomi, Pirkanmaa, Etelä-Savo, Etelä-Pohjanmaa, Keski-Suomi, Pohjois-Savo, Pohjois-Karjala, Kainuu, Pohjois-Pohjanmaa, Lappi, Rannikko (pohjanmaa), Rannikko (etelärannikko)",
sub = "Kantohinta-arvo Käytönrajoitus: Puuntuotannon ulkopuolella",
font.main=2,cex.main=0.9,cex.sub=0.9)
legend(2730000,7315000,
title="1000eur",legend=names(attr(colcode,"table")),
fill=attr(colcode,"palette"),
border="black", cex=0.8,bty="o", xpd="FALSE")
dev.off()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我已经快速运行了代码:实际的转换似乎是通过这一行完成的:
nres <- character(lx - 1)
在
tableClassIntervals
的代码中(classInt )。您可以检查此函数,发现它只是忽略了它的
digits
参数。您可能想将此信号告知包作者。不过:正如@Gavin 所说,可重复性会很好。
I've done a quick run through the code: the actual conversion appears to be done by this line:
nres <- character(lx - 1)
In the code for
tableClassIntervals
(ofclassInt
). You can check this function to see that it simply ignores itsdigits
argument. You might want to signal this to the package authors.Still: as @Gavin said, reproducibility would be nice.
尝试将
scipen
选项设置为正数,而不是 oddigits
:但是很难看出这是否能解决问题,因为您的代码无法工作,因为我们不这样做没有形状文件。
Try setting the
scipen
option to a positive number instead oddigits
:but it is difficult to see if this will solve the problem as your code doesn't work because we don't have the shapefile.