[R] Adding Two-Headed Arrow in map legend
David Winsemius
dwinsemius at comcast.net
Sun Apr 10 19:10:02 CEST 2016
> On Apr 10, 2016, at 4:12 AM, Miluji Sb <milujisb at gmail.com> wrote:
>
> Hello David,
>
> This is exactly what I want but I still can't get the arrows. R and R studio is updated. Thanks again!
I didn't try it in Rstudio until just now (and I don't remember that you ever mentioned RStudio as a possible issue.) The plotting I see in the default graphics Rstudio window is rather different than what I see in the default plotting window for the R.app GUI. I'm guessing you are reporting results from viewing plots in that IDE's viewing window.
I would try plotting with the png() or pdf() devices and see if the results are more predictable. I just tried with pdf() from RStudio and the results were much closer to what I was seeing with saving from R.app. The `quartz()` device seems to deliver consistent results for me. The RStudio device is something they call RStudioGD, and I don't have sufficient experience to explain its quirks.
--
David.
>
> Sincerely,
>
> Milu
>
> On Sat, Apr 9, 2016 at 10:29 PM, David Winsemius <dwinsemius at comcast.net> wrote:
>
> > On Apr 9, 2016, at 1:27 PM, David Winsemius <dwinsemius at comcast.net> wrote:
> >
> >
> >> On Apr 9, 2016, at 11:18 AM, David Winsemius <dwinsemius at comcast.net> wrote:
> >>
> >>
> >>> On Apr 9, 2016, at 10:46 AM, Miluji Sb <milujisb at gmail.com> wrote:
> >>>
> >>> Dear David,
> >>>
> >>> Thank you for your answer. Sorry for the embarrassing mistake. However, even with when I generate a map for the whole world using:
> >>>
> >>> eps <- mapCountryData(n, nameColumnToPlot="eps_score", mapTitle="EPS Score",colourPalette=colourPalette,
> >>> catMethod="fixedWidth", missingCountryCol = "white", addLegend=FALSE)
> >>>
> >>> And then use:
> >>>
> >>> do.call(addMapLegend, c(eps, legendLabels="none", arrows(-100,-140,100,-140,code=3)))
> >>
> >> I do get an arrow using same version of R and OSX. See attached. (I think that png images will be accepted by the mailserver.)
> >
> > Nope I was wrong, but the copy to Milugi did arrive.
> >
> > Here's a (somewhat larger) pdf:
>
>
>
>
> >
> >
> > --
> > David
> >>
> >>
> >>
> >> --
> >> David.
> >>>
> >>> Only a legend with the colours is generated, no arrows. My session info is below. Thanks again!
> >>>
> >>> R version 3.2.4 (2016-03-10)
> >>> Platform: x86_64-apple-darwin13.4.0 (64-bit)
> >>> Running under: OS X 10.11.2 (El Capitan)
> >>>
> >>> locale:
> >>> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
> >>>
> >>> attached base packages:
> >>> [1] stats graphics grDevices utils datasets methods base
> >>>
> >>> other attached packages:
> >>> [1] countrycode_0.18 ggplot2_2.1.0 RColorBrewer_1.1-2 foreign_0.8-66 maptools_0.8-39 rworldmap_1.3-6
> >>> [7] sp_1.2-0
> >>>
> >>> loaded via a namespace (and not attached):
> >>> [1] Rcpp_0.12.4 lattice_0.20-33 grid_3.2.4 plyr_1.8.3 gtable_0.2.0 spam_1.3-0
> >>> [7] scales_0.4.0 tools_3.2.4 munsell_0.4.3 maps_3.1.0 fields_8.3-6 colorspace_1.2-6
> >>>
> >>> On Sat, Apr 9, 2016 at 7:34 PM, David Winsemius <dwinsemius at comcast.net> wrote:
> >>>
> >>>> On Apr 9, 2016, at 8:13 AM, Miluji Sb <milujisb at gmail.com> wrote:
> >>>>
> >>>> Forgot to copy the list
> >>>>
> >>>> Dear Jim,
> >>>>
> >>>> Thank you for your reply. I must be doing something wrong, If this is my
> >>>> command to plot a map of Europe:
> >>>>
> >>>> eps_europe <- mapCountryData(n, nameColumnToPlot="eps_score", mapTitle="EPS
> >>>> Score - Europe",colourPalette=colourPalette,
> >>>> catMethod="fixedWidth", missingCountryCol =
> >>>> "white", mapRegion="Europe", addLegend=FALSE)
> >>>>
> >>>> The following command does not seem to add the arrow. What am I doing wrong?
> >>>>
> >>>> do.call(addMapLegend, c(eps_europe, legendLabels="none",
> >>>> arrows(-100,-140,100,-140,code=3)))
> >>>>
> >>>
> >>> Your earlier question had a full world map. That was the context for Jim's reply, which did plot a two headed arrow above the legend in your earlier question. Now you have restricted the plot region to Europe so the coordinates of -100,-140,100,-140 no longer are on the visible plot area. You need to decide where you want the arrows using sensible coordinates.
> >>>
> >>> --
> >>> David.
> >>>
> >>>
> >>>> Thank you again. I really appreciate it.
> >>>>
> >>>> Sincerely,
> >>>>
> >>>> Milu
> >>>>
> >>>> On Sat, Apr 9, 2016 at 12:20 PM, Jim Lemon <drjimlemon at gmail.com> wrote:
> >>>>
> >>>>> Hi Miluji,
> >>>>> Try this:
> >>>>>
> >>>>> arrows(-100,-140,100,-140,code=3)
> >>>>>
> >>>>> Jim
> >>>>>
> >>>>>
> >>>>> On Fri, Apr 8, 2016 at 10:24 PM, Miluji Sb <milujisb at gmail.com> wrote:
> >>>>>> I am trying to draw maps for the world using:
> >>>>>>
> >>>>>> library(rworldmap)
> >>>>>> library(maptools)
> >>>>>> library(RColorBrewer)
> >>>>>>
> >>>>>>
> >>>>>> tmp2<- dput(head(pece,10))
> >>>>>> structure(list(iso3 = c("AUS", "AUT", "BEL", "CAN", "CHE", "CHL",
> >>>>>> "CZE", "DEU", "DNK", "ESP"), eps_score = c(0.877343773841858,
> >>>>>> 2.68984365463257, 1.31406247615814, 1.98046875, 2.61666655540466,
> >>>>>> NA, 1.44414067268372, 2.34257817268372, 2.89687490463257,
> >>>>> 2.15937495231628
> >>>>>> ), gov_eff = c(1.76499999562899, 1.85666667421659, 1.74500000476837,
> >>>>>> 1.88416666785876, 1.99181815710935, 1.21499997377396, 0.865833342075348,
> >>>>>> 1.64999999602636, 2.15416664878527, 1.36833332975705), sh_va_enint =
> >>>>>> c(13.4375638961792,
> >>>>>> 8.90904521942139, 10.368335723877, 14.0469560623169, NA, NA,
> >>>>>> 13.5679216384888, 9.67090892791748, 10.5978908538818, 8.34146690368652
> >>>>>> ), rd_in_va = c(2.17547988891602, 2.47147130966187, 2.53955459594727,
> >>>>>> 2.01138758659363, NA, NA, 1.49587619304657, 2.72330951690674,
> >>>>>> 2.5316367149353, 1.48551619052887)), datalabel = "", time.stamp = " 9 Mar
> >>>>>> 2016 17:43", .Names = c("iso3",
> >>>>>> "eps_score", "gov_eff", "sh_va_enint", "rd_in_va"), formats = c("%9s",
> >>>>>> "%8.0g", "%10.0g", "%9.0g", "%9.0g"), types = c(6L, 254L, 255L,
> >>>>>> 254L, 254L), val.labels = c("", "", "", "", ""), var.labels = c("",
> >>>>>> "(mean) eps_score", "(mean) gov_eff", "(mean) sh_va_enint", "(mean)
> >>>>>> rd_in_va"
> >>>>>> ), expansion.fields = list(c("_dta", "ReS_i", "countrycode"),
> >>>>>> c("_dta", "ReS_ver", "v.2"), c("_dta", "ReS_j", "year"),
> >>>>>> c("_dta", "ReS_str", "0"), c("_dta", "ReS_Xij", "a_"), c("_dta",
> >>>>>> "__JVarLab", "ACT"), c("_dta", "__XijVarLabrdd_", "(sum) rdd"
> >>>>>> ), c("_dta", "__XijVarLabp", "Value"), c("_dta", "__XijVarLabpop",
> >>>>>> "Population"), c("_dta", "__XijVarLabest_lu_f", "Source of lu"
> >>>>>> ), c("_dta", "__XijVarLablu", "Percentage of No Schooling"
> >>>>>> ), c("_dta", "__XijVarLabest_lp_f", "Source of lp"), c("_dta",
> >>>>>> "__XijVarLablp", "Percentage of Primary"), c("_dta", "__XijVarLablh",
> >>>>>> "Percentage of Tertiary"), c("_dta", "__XijVarLabest_lh_f",
> >>>>>> "Source of lh"), c("_dta", "__XijVarLabls", "Percentage of Secondary"
> >>>>>> ), c("_dta", "__XijVarLabest_ls_f", "Source of ls"), c("_dta",
> >>>>>> "__XijVarLabvalue", "Value"), c("_dta", "_TStvar", "year"
> >>>>>> ), c("_dta", "_TSpanel", "id2"), c("_dta", "_TSdelta",
> >>>>>> "+1.0000000000000X+000"
> >>>>>> ), c("_dta", "_TSitrvl", "1"), c("_dta", "tis", "year"),
> >>>>>> c("_dta", "iis", "id2")), version = 12L, row.names = c("1",
> >>>>>> "2", "3", "4", "5", "6", "7", "8", "9", "10"), class = "data.frame")
> >>>>>> n <- joinCountryData2Map(pece, joinCode="ISO3", nameJoinColumn="iso3")
> >>>>>> n <- n[-which(row.names(n)=='Antarctica'),]
> >>>>>>
> >>>>>> # EPS
> >>>>>> colourPalette <- rev(brewer.pal(7, "RdYlGn"))
> >>>>>>
> >>>>>> eps <- mapCountryData(n, nameColumnToPlot="eps_score", mapTitle="EPS
> >>>>>> Score",colourPalette=colourPalette,
> >>>>>> catMethod="fixedWidth", missingCountryCol =
> >>>>> "white",
> >>>>>> addLegend=FALSE)
> >>>>>> do.call(addMapLegend, c(eps, legendLabels="all", legendWidth=0.5))
> >>>>>>
> >>>>>> Instead of adding numeric based legend, I would like to add a two-headed
> >>>>>> arrow with some text. I would be grateful for any help. Thank you!
> >>>>>>
> >>>>>> Sincerely,
> >>>>>>
> >>>>>> Milu
> >>>>>>
>
>
>
David Winsemius
Alameda, CA, USA
More information about the R-help
mailing list