#' Generate land use transition data for area of interest.
#'
#' A function that generate land use transitions from year1 to year2 for area of interest.
#'
#' @param data Land use change data generated by the \code{rotate} function.
#' @param top Top land use types.
#'
#' @return
#' The function returns a ggplot object.
#'
#' @export
#'
#'
plotRot <- function(data, top = 5){
data <- as.data.frame(data)
topuse <- dplyr::filter(data, value.x != 0, value.y != 0)
topuse <- dplyr::group_by(topuse, value.x)
topuse <- dplyr::summarise(topuse, counts = sum(counts))
topuse <- dplyr::arrange(topuse, dplyr::desc(counts))
fsuse <- topuse$value.x[1:top]
datasub <- dplyr::filter(data, value.x %in% fsuse, value.y %in% fsuse)
datasub <- dplyr::mutate(datasub, value.x = as.character(value.x),
value.y := as.character(value.y))
g <-
ggplot2::ggplot(datasub, ggplot2::aes(value.y, value.x, fill= counts)) +
ggplot2::geom_tile() +
viridis::scale_fill_viridis(discrete=FALSE) +
ggplot2::labs(x = 'Land use category in year 2', y = 'Land use category in year 1') +
ggplot2::coord_fixed() +
ggplot2::theme_minimal() +
ggplot2::theme(axis.text = ggplot2::element_text(colour = 'black'),
legend.position = 'right')
return(g)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.