Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Graphic not appearing in R: null device?

I'm trying to produce a graphic using rworldmap, using my data frame dagg. ETA: data. Here's what I have so far.

library(rworldmap)
data(dagg)
sPDF <- joinCountryData2Map(dagg, joinCode='ISO2',
nameJoinColumn='country', verbose='TRUE')

mapDevice()

mapCountryData(sPDF, nameColumnToPlot='avoidance', 
numCats=10, mapTitle="Avoidance", addLegend=TRUE)
dev.off()

But when I run, nothing shows up. The console displays "null device 1". It was working just now, and I'm not sure what could have changed it...

Perhaps I'm not using the right device?

ETA: Here's the rundown on rworldmap that I'm reading from.

like image 963
Anshu says Reinstate Monica Avatar asked May 05 '15 00:05

Anshu says Reinstate Monica


People also ask

What does null device mean in R?

There is a "null device" which is always open but is really a placeholder: any attempt to use it will open a new device specified by getOption("device") . Devices are associated with a name (e.g., "X11" or "postscript" ) and a number in the range 1 to 63; the "null device" is always device 1.

What does Dev OFF () do in R?

dev. off shuts down the specified (by default the current) device. If the current device is shut down and any other devices are open, the next open device is made current.

What is the default screen margin for a graphics device in R?

The default value of mgp is c(3,1,0), which means that the axis title is drawn in the fourth line of the margin starting from the plot region, the axis labels are drawn in the second line and the axis line itself is the first line.


1 Answers

dev.off() closes the currently active graphics device, so if you are running all of that code at once, the map will be plotted and then almost immediately disappear, with the typical output:

## null device 
##           1 

Running the following, which excludes dev.off(), should produce the map you're expecting.

library(rworldmap)
dagg <- read.csv(
  'http://raw.githubusercontent.com/pourque/country-data/master/data/dagg.csv')
sPDF <- joinCountryData2Map(dagg, joinCode='ISO2',
                            nameJoinColumn='country', verbose='TRUE')

mapDevice()   
mapCountryData(sPDF, nameColumnToPlot='avoidance', 
               numCats=10, mapTitle="Avoidance", addLegend=TRUE)

enter image description here

like image 194
jbaums Avatar answered Oct 19 '22 10:10

jbaums