barplotCountryData: Barplot country-level data.

View source: R/barplotCountryData.r

barplotCountryDataR Documentation

Barplot country-level data.

Description

Draw a barplot of country-level data, ranking the countries to allow easy comparison. One bar per country and to be able to read country names. This is useful for comparing with maps created by mapCountryData and accepts many of the same arguments for categorising and colouring.

Usage

barplotCountryData(
  dF = "",
  nameColumnToPlot = "",
  nameCountryColumn = "NAME",
  numPanels = 4,
  scaleSameInPanels = FALSE,
  main = nameColumnToPlot,
  numCats = 5,
  catMethod = "quantiles",
  colourPalette = "heat",
  addLegend = TRUE,
  toPDF = FALSE,
  outFile = "",
  decreasing = TRUE,
  na.last = TRUE,
  cex = 0.7,
  ...
)

Arguments

dF

a dataframe containing at least one column with numeric data and one with country names or other labels

nameColumnToPlot

name of column containing the data you want to plot

nameCountryColumn

name of column containing country names (or other labels to be used in plot)

numPanels

the number of layout panels in the plot

scaleSameInPanels

whether to set the scale the same in each panel TRUE/FALSE, default=FALSE allowing more of the variability in the data to be viewed

main

title for the plot

numCats

number of categories to put the data in, may be modified if this number is incompatible with the catMethod chosen

catMethod

method for categorisation of data "pretty", "fixedWidth", "diverging", "logFixedWidth","quantiles","categorical", or a numeric vector defining breaks

colourPalette

a string describing the colour palette to use, choice of :

  1. = "palette" for the current palette

  2. a vector of valid colours, e.g. =c('red','white','blue') or output from RColourBrewer

  3. = one of "heat", "diverging", "white2Black", "black2White", "topo", "rainbow", "terrain", "negpos8", "negpos9"

addLegend

NOT YET WORKING whether to add a legend or not, TRUE/FALSE

toPDF

whether to output the plot to a pdf rather than the screen, TRUE/FALSE

outFile

output filename if toPDF=TRUE

decreasing

logical. Should the sort order be increasing or decreasing?

na.last

for controlling the treatment of NAs. If TRUE, missing values in the data are put last; if FALSE, they are put first; if NA, they are removed.

cex

sizing of labels, default = 0.7

...

other arguments to pass to barplot

Details

Finer control can be achieved by addMapLegend.

Value

invisibly returns a list containing the data and main options used for the map, the list can be passed to addMapLegend or addMapLegendBoxes along with additional options to allow greater flexibility in legend creation.

Warning

will generate unhelpful errors in data categorisation if inappropriate options are chosen, e.g. with catMethod:Quantiles if numCats too high so that unique breaks cannot be defined.

Author(s)

andy south

See Also

classInt, RColorBrewer

Examples


#default uses popn data in the default map
barplotCountryData()


data("countryExData",envir=environment(),package="rworldmap")

barplotCountryData( countryExData
              , nameColumnToPlot="BIODIVERSITY" 
              , nameCountryColumn = "Country"
              )
              

              


rworldmap documentation built on Oct. 16, 2023, 5:07 p.m.