0

我目前正在使用 bfastSpatial,我正在尝试将断点值绘制为基于年份颜色的图例。我知道用于绘制每月断点的 changeMonth 函数(http://www.loicdutrieux.net/bfastSpatial/)但是,我试图实现与 Morrison 等人类似的结果。(2019) https://www.mdpi.com/2072-4292/10/7/1075 任何帮助将不胜感激。 在此处输入图像描述

4

1 回答 1

0

如果要将断点日期四舍五入为整数年,可以使用floor,因为日期是十进制年。接下来,要制作与您展示的类似的图,您可以使用该tmap包。由于您没有将任何数据附加到 OP,因此我使用了包tura中包含的数据。bfastSpatial

library(bfastSpatial)
library(tmap)

# Load tura data
data(tura)
# Perform bfast analysis
bfm <- bfmSpatial(tura, start=c(2009, 1), order=1)

# Extract the first band (breakpoints)
change <- bfm[[1]]

# As breakpoints dates are in year decimals,
# you can use floor to round them to lowest integer
change <- floor(change)

# Set shape as change, the object to plot
tm_shape(change) +
  # Plot it as raster and set the palette, number of categories,
  # style (categorical) and title of the legend.
  tm_raster(palette = "Spectral",
            n = 5,
            style = "cat",
            title = "Year") +
  # Set the legend's position and eliminate the comma used by default for
  # separating thousands values. Add background color and transparency
  tm_layout(legend.position = c("right", "bottom"),
            legend.format=list(fun=function(x) formatC(x, digits=0, format="d")),
            legend.bg.color = "white",
            legend.bg.alpha = 0.7) +
  # Add scale bar, set position and other arguments
  tm_scale_bar(breaks = c(0,0.5,1),
               position = c("right", "top"),
               bg.color = "white",
               bg.alpha = 0.7) +
  # Add north arrow with additional parameters
  tm_compass(type = "arrow", 
             position = c("left", "top"),
             bg.color = "white",
             bg.alpha = 0.7) 

得到的情节: 断点图

于 2021-09-05T04:19:11.920 回答