Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

Is it possible to create a bubble map in R based on simple dataframe information per continents?

$
0
0

I want to create a bubble map, using a simple data frame, extracted from a survey, and show it as info per continents. Most of the libraries I found use country-level info or x-y coordinates.

I already calculate the count to have the final number for each bubble, so I have this data:user_location count

<chr>                 <dbl>1 Africa                    12 Asia                      33 Europe                   134 North America             85 South America           122

The only library I found with the possibility of showing Continent info is rworldmap

install.packages("rworldmap")library(rworldmap)sPDF <- getMap()mapCountryData(sPDF, nameColumnToPlot='REGION')

enter image description here(Using 'REGION' I have a model with 7 continents, more accurate to the data I have)

The next thing I did was to merge my data with sPDF which is a SpatialPolygonsDataFrame, I found this code here and adapted to my needs:

sPDF@data = data.frame(sPDF@data, df[match(sPDF@data["REGION"], df["user_location"])])

But I'm getting this error, because sPDF@data["REGION"] has a NA value

Can't subset columns with match(sPDF@data["REGION"], df["user_location"]).Subscript match(sPDF@data["REGION"], df["user_location"]) can't contain missing values.It has a missing value at location 1.

Question 1: Is this approach correct? Is there an easy way to add personal data to SpatialPolygonsDataFrame, like a function I could be missing?

Question 2: Once I solve this problem, I'm planning to use 'mapBubbles' function, from the same library, like this:mapBubbles(sPDF, nameZSize = "count", mapRegion = "REGION")Is this correct?

Sorry if I add 2 questions in 1, it's my first time with R and I've been stuck with this map for over a week.


Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>