plot_trend {rnrfa}R Documentation

Plot trend

Description

This function plots a previously calculated trend.

Usage

plot_trend(df, column_name, maptype = "stamen_toner_lite", showmap = TRUE)

Arguments

df

Data frame containing at least 4 column: lat (latitude), lon (longitude), slope and an additional user-defined column column_name.

column_name

name of the column to use for grouping the results.

maptype

maptype, was need to choose the stamenmap type, now useless since stamenmap are no longer reachable

showmap

set to FALSE to avoid plotting the map when running the function

Details

The function relies on the 'ggmap' package for the map, and this package has in time gone through many changes due to changes in API of map providers. Currently to be able to create the map one needs to register to the stadiamaps serice. More information at ?ggmap::register_stadiamaps().

Value

Two plots, the first showing the distribution of the trend over a map, based on the slope of the linear model that describes the trend. The second plot shows a boxplot of the slope grouped based on the column column_name and slope can be user-defined (notice that in the plot the very extreme slope values are not displayed to avoid skewed visualisations).

Examples

## Not run: 
  # some fake data around London 
  df <- data.frame(lat = 51.5+runif(40,-0.3,0.3), 
                   lon = 0+runif(40, -0.3,0.3),
                   slope = rnorm(40, c(rep(-0.4,20),rep(0.4,20))), 
                   g = factor(c(rep("a",20), rep("b",20))))
  theplots <- plot_trend(df, "g", maptype = "terrain-background")
  theplots$A # map
  theplots$B + labs(subtitle = "Use ggplot usual commands to modify the plots") # boxplots
  

## End(Not run)

[Package rnrfa version 2.1.0.5 Index]