简体   繁体   中英

Plot numbers / data points onto a World Map using RSCript

Using RSCript and the rworldmap package. I would like to create an output to be able to show the no of documents published within each company. Roughly based around mapPies but instead of using pie charts to be able to just display the data on the chart.

I have my own txt file that has 3 columns - ISO3V10, Country and No of Documents.

ISO3V10 Country              No of Documents
CAN     Canada               30
CHN     China                20
RUS     Russia               10
GBR     United Kingdom       38
USA     United States        50

For United States the number 50 would appear and United Kingdom 38 etc... On the image shown below!!!!

I have images of I would like it to look like but I cant post any images, happy to send if need clarification

I have created a world map using RSCript and rworldmap so to apply code that does that would be brilliant.

The code I used to generate the world map is as follows:

library(rworldmap) 
require(rworldmap)
myData2 <- read.delim(file="C:\\Documents\\Projects\\RScriptAnalysis\\noofpublications2.txt", header = TRUE, sep = "\t")
names(myData2)
sPDF2 <- joinCountryData2Map(myData2, joinCode = "ISO3", nameJoinColumn = "ISO3V10")
par(mai=c(0,0,0.2,0),xaxs="i",yaxs="i")
mapParams <- mapCountryData(sPDF2, nameColumnToPlot="No.of.Documents", catMethod = "categorical", addLegend=FALSE)
do.call( addMapLegend, c(mapParams, legendWidth=0.5, legendMar = 2))

If this possible to do using RSCript and rworldmap can you write the code or adapt my code that allows me to do this?


This is what I would like to be able to do!

Where can I find out the longitude and latitude as this would be better.

As the output I would like is the number of documents displayed on the map for each country!

Would you be able to edit my file and code above in the original question to show me how to do this?

Is it possible? This is R.

require(fortunes)
fortune("Yoda")

You may need to be more specific about exactly where you want these numbers since the merger gets you more than 5 areas:

str(sPDF2@data[which(sPDF2@data$ISO3V10 =="GBR"),])
'data.frame':   1 obs. of  15 variables:
 $ FIPS        : Factor w/ 244 levels "","AC","AE","AF",..: 224
 $ ISO2        : Factor w/ 246 levels "AD","AE","AF",..: 76
 $ ISO3        : Factor w/ 246 levels "ABW","AFG","AGO",..: 79
 $ UN          : int 826
 $ NAME        : Factor w/ 246 levels "Afghanistan",..: 230
 $ AREA        : int 24193
 $ POP2005     : int 60244834
 $ REGION      : int 150
 $ SUBREGION   : int 154
 $ LON         : num -2.9
 $ LAT         : num 54.2
 $ ISO3V10     : Factor w/ 5 levels "CAN","CHN","GBR",..: 3
 $ Country     : Factor w/ 5 levels "Canada","China",..: 4
 $ No_Documents: int 38
 $ ISO3        : Factor w/ 5 levels "CAN","CHN","GBR",..: 3

So why not provide coordinates for the locations where you want these numbers placed and and edit your input file to reflect that choice.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM