Это код и данные. Не работает только ggplot, цвета. Я пытаюсь много раз, но раньше у меня не было этой https://www.metoffice.gov.uk/hadobs/hadcrut4/data/current/time_series/HadCRUT.4.6.0.0.annual_ns_avg.txt* проблемы **.
library(ggplot2)
library(RColorBrewer)
library(tidyverse)
library(grid)
library(utils)
library(readr)
url <- "https://www.metoffice.gov.uk/hadobs/hadcrut4/data/current/time_series/HadCRUT.4.6.0.0.annual_ns_avg.txt"
download.file(url,"HadCRUT.4.6.0.0.annual_ns_avg")
unzip("HadCRUT.4.6.0.0.annual_ns_avg")
setwd(..)
HadCRUT.4.6.0.0.annual_ns_avg <-read.table("HadCRUT.4.6.0.0.annual_ns_avg.txt", sep=",", header= F)
dput(HadCRUT.4.6.0.0.annual_ns_avg)
make_gradient <- function(deg = 45, n = 100, cols = blues9) {
cols <- colorRampPalette(cols)(n + 1)
rad <- deg / (180 / pi)
mat <- matrix(
data = rep(seq(0, 1, length.out = n) * cos(rad), n),
byrow = TRUE,
ncol = n) +
matrix(
data = rep(seq(0, 1, length.out = n) * sin(rad), n),
byrow = FALSE,
ncol = n
)
mat <- mat - min(mat)
mat <- mat / max(mat)
mat <- 1 + mat * n
mat <- matrix(data = cols[round(mat)], ncol = n)
grid::rasterGrob(
image = mat,
width = unit(1, "npc"),
height = unit(1, "npc"),
interpolate = TRUE
)
}
mediat <- grafico %>%
summarize(media = mean(V1))
g <- make_gradient(deg = 180, n = 500, cols = rev(brewer.pal(9, "RdBu")))
ggplot(grafico, aes(V1)) +
annotation_custom(grob = g, xmin = -Inf, xmax = Inf, ymin = -Inf, ymax = Inf) +
geom_density(fill="azure1")+
geom_vline(data = mediat, aes(xintercept = media), size = 0.7)