开发者

Values in R legends are shortened to Ne+n form

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 &开发者_JAVA技巧lt;- 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()


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 (of classInt). You can check this function to see that it simply ignores its digits argument. You might want to signal this to the package authors.

Still: as @Gavin said, reproducibility would be nice.


Try setting the scipen option to a positive number instead od digits:

opts <- options(scipen = 10)

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜