rworldmap in R markdown knitr

515 views
Skip to first unread message

fan....@gmail.com

unread,
Oct 20, 2014, 10:36:22 PM10/20/14
to rwor...@googlegroups.com
Hi, I want to use the map produced from rworldmap in a R markdown file, to knit to HTML.

For some reason the map does not show. I only got a message:

ERROR: invalid number of intervals

Anyone tried to use rworldmap in Knitr?


My code is as follows:

library(rworldmap)
colourPalette1 <-c("#F5A9A9", "#F6D8CE", "#F8ECE0", "#EFFBFB", "#E0F2F7", "#CEE3F6", "#A9BCF5")

world <- joinCountryData2Map(wvs_c
                             ,joinCode = "ISO3"
                             ,nameJoinColumn = "iso3"
                             ,mapResolution="li"
                             ,verbose=FALSE)

mapCountryData(world, colourPalette=colourPalette1      
               ,mapTitle='Percent of respondents belonging to an association'
               ,nameColumnToPlot='participation')


Andy South

unread,
Oct 21, 2014, 5:11:48 AM10/21/14
to fan....@gmail.com, rwor...@googlegroups.com
Hello there.
I have used rworldmap with knitr and markdown and it has been OK.

Do you get the same error when you use direct from R ?

The error suggests it could be something to do with the number of categories (numCats) from mapCountryData.

If you can post a link to the data I may be able to help more.

Best wishes,
Andy

--
You received this message because you are subscribed to the Google Groups "rworldmap" group.
To post to this group, send email to rwor...@googlegroups.com.
Visit this group at http://groups.google.com/group/rworldmap.
To view this discussion on the web, visit https://groups.google.com/d/msgid/rworldmap/a22e259d-0956-4862-8003-942e9b88b000%40googlegroups.com.

fan....@gmail.com

unread,
Oct 21, 2014, 12:16:04 PM10/21/14
to rwor...@googlegroups.com, fan....@gmail.com
Hi,

Actually after I restarted my computer this morning, it works. To be specific, I am using r markdown to create a slidify presentation.

I have another question- is there anyway to suppress a message like this:

82 codes from your data successfully matched countries in the map
3 codes from your data failed to match with a country code in the map
96 codes from the map weren't represented in your data

I tried 

r, echo=FALSE, comment=NULL, message=FALSE, warning=FALSE

and making "verbose=FALSE" in the joinCountryData2Map function,
but none of works.

Thanks!

Andy South

unread,
Oct 23, 2014, 8:29:32 AM10/23/14
to rwor...@googlegroups.com, Peggy Fan

Thanks ! Good to hear.
I'm forwarding this to the group so that the solution is there.

---------- Forwarded message ----------
From: Peggy Fan <fan....@gmail.com>
Date: 22 October 2014 18:46
Subject: Re: [rworldmap group] rworldmap in R markdown knitr
To: Andy South <sout...@gmail.com>


It worked! Thanks so much!

On Wed, Oct 22, 2014 at 10:42 AM, Andy South <sout...@gmail.com> wrote:

Hello there, I'm away from my computer for a couple of days, I'll try to have a look for you when I get back. I think I did something by putting the join* that produces the message into a separate chunk and not displaying any of the outputs from it.
Andy

On Oct 22, 2014 6:17 PM, "Peggy Fan" <fan....@gmail.com> wrote:
Hi Andy,

I have another question- is there anyway to suppress a message like this:

"82 codes from your data successfully matched countries in the map
3 codes from your data failed to match with a country code in the map
96 codes from the map weren't represented in your data"


I tried 

r, echo=FALSE, comment=NULL, message=FALSE, warning=FALSE

and making "verbose=FALSE" in the joinCountryData2Map function,
but none of works.

Thanks!

Sandipayan Nandi

unread,
Dec 6, 2014, 2:11:30 AM12/6/14
to rwor...@googlegroups.com, fan....@gmail.com, sout...@gmail.com

Andy/Peggy, 

I am using  'R Presentation' from R Studio  to create a slide show for my project. I am using the below code and whatever I do I am not able to get rid of the  output message from the code. I do not want the progress message to be included in my presentation slide.

Seems like Peggy had the same problem and you suggested to  have the below portion of code in a different chunk , but that did not help me either.  I cleared cache and tried all stuffs, but could not get  rid of the progress message. 

Can you please help ?


```{r, echo=FALSE}

sPDF <- joinCountryData2Map(subset(world_all, year==year.list[i])
                              ,joinCode = "ISO3"
                              ,nameJoinColumn = "country_code" 
                              , mapResolution = "coarse"
                              ,verbose=FALSE)

```

154 codes from your data successfully matched countries in the map
0 codes from your data failed to match with a country code in the map
90 codes from the map weren't represented in your data



Thanks
Sandipayan

Peggy Fan

unread,
Dec 8, 2014, 12:47:07 PM12/8/14
to Sandipayan Nandi, rwor...@googlegroups.com, Andy South
Hi Sandipayan,
I will give you my codes- I think the trick is to separate them into different chunks (see below). Hope this helps.


```{r, echo=FALSE, comment=NULL, message=FALSE, warning=FALSE, results='hide'}

library(rworldmap)

wvs_c <- read.csv("/Users/peggyfan/Downloads/R_data/Developing_data_products/wvs_c")
wvs_c <- wvs_c[, -1]

colourPalette1 <-c("#F5A9A9", "#F6D8CE", "#F8ECE0", "#EFFBFB", "#E0F2F7", "#CEE3F6", "#A9BCF5")
world <- joinCountryData2Map(wvs_c
                             ,joinCode = "ISO3"
                             ,nameJoinColumn = "iso3"
                             ,mapResolution="li")
```

```{r, echo=FALSE, comment=NULL, message=FALSE, warning=FALSE, fig.height=6, fig.width=10}

mapCountryData(world, colourPalette=colourPalette1      
               ,mapTitle='Percent of respondents belonging to an association'
               ,nameColumnToPlot='participation')
```


sandipayan nandi

unread,
Dec 8, 2014, 12:59:56 PM12/8/14
to Peggy Fan, rwor...@googlegroups.com, Andy South
Thanks Peggy !

I went to the source code of the rworldmap and saw that Andy is using a ‘cat’ command to print those messages . So I could mute those simply by  doing the following ( capture.output  &  file= ’NUL’ )  :


capture.output(sPDF <- joinCountryData2Map(subset(world_all, year==year.list[i])
                                           ,joinCode = "ISO3"
                                           ,nameJoinColumn = "country_code"
                                           , mapResolution = "coarse"
                                           ,verbose=FALSE) , file='NUL'
)



- Sandipayan
Reply all
Reply to author
Forward
0 new messages