If you really want to mix base and grid graphics (they don't play
nicely together as you have noticed) then you should really use the
gridBase package. There is at least one package for doing maps using
grid (ggmap or ggMaps or something similar) and there is the regular
text function for adding text to a base graph, either of those may be
easier than mixing.
Since you are plotting the map after the text, whether the text is
visible or not depends on the background drawn for the map, I expect
that this differs for the different devices. Would you be surprised
if you wrote some text on a piece of paper, then layed a paper map
over the top and could not read the paper? If you want the text
visible on top of the map, do the text after the map.
On Sun, Jun 29, 2014 at 5:56 PM, Spencer Graves
<spencer.graves at structuremonitoring.com> wrote:> I'm confused with the results I'm getting from mixing grid
and
> traditional graphics. A toy example appears below: The png file created
by
> gridFn() shows "a label" over Africa, as expected. However, when
run
> interactively, "a label" appears for roughly half a second, then
disappears.
>
>
> Can someone explain these results?
>
>
> Thanks,
> Spencer
>
>
> gridFn <- function(){
> pushViewport(plotViewport())
> grid.text(label='a label')
> popViewport()
> map()
> }
>
> library(grid)
> library(maps)
> gridFn()
>
> png('gridTst.png')
> gridFn()
> dev.off()
>
>
>> sessionInfo()
> R version 3.1.0 (2014-04-10)
> Platform: i386-w64-mingw32/i386 (32-bit)
>
> locale:
> [1] LC_COLLATE=English_United States.1252
> [2] LC_CTYPE=English_United States.1252
> [3] LC_MONETARY=English_United States.1252
> [4] LC_NUMERIC=C
> [5] LC_TIME=English_United States.1252
>
> attached base packages:
> [1] grid stats graphics grDevices utils datasets methods
> [8] base
>
> other attached packages:
> [1] maps_2.3-7
>
> loaded via a namespace (and not attached):
> [1] tools_3.1.0
>>
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
--
Gregory (Greg) L. Snow Ph.D.
538280 at gmail.com