【发布时间】:2020-01-27 06:01:21
【问题描述】:
我有一个包含降水量和温度的天气文件,我将其编码为将整个数据集绘制成四个类别:凉爽和潮湿、凉爽和干燥、温暖和潮湿以及温暖和干燥。我想知道是否可以为每个类别引入特定的颜色。我做不到
年雨温度 87 91.4 10.4 88 133.3 10.9 89 106 10.64 90 59.12 12.6 91 99 9.9 92 145.36 10.51 93 133.3 10.89 94 133 10.8 95 122 10.09 96 162 8.7 97 250 11.06 98 133 10.5 99 27 10.4 0 138 11 1 182 12.8 2 138 10 3 129 10.3 4 142 12.5 5 114 13.3 6 102 10.3 7 193 11.8 8 242 10.6 9 139 10.1 10 80.41 4.05 11 56.64 11.1 12 58.24 11.3 13 141.26 11.56 14 76.7 10.3 15 87.28 10.4 16 147.7 13.2 17 154.8 11.8 126.3390323 10.76774194
我把它编码为:
library(ggplot2)
setwd('C:/Users/nchatterjee2/Desktop')
data <- read.csv("Fall.csv", header=TRUE, sep=",",row.names=NULL, fill = T)
limit_humid <- 128
limit_warm <- 11
head(data)
ggplot(data, aes(x = temp, y = rain)) +
geom_text(aes(label = Year))+
geom_vline(xintercept = limit_warm) +
geom_hline(yintercept = limit_humid) +
annotate('text', label = 'bold("Cool and Wet")', size = 3, parse = T,
x = min(data$temp), y = max(data$rain)) +
annotate('text', label = 'bold("Warm and Wet")', size = 3, parse = T,
x = max(data$temp), y = max(data$rain)) +
annotate('text', label = 'bold("Cool and Dry")', size = 3, parse = T,
x = min(data$temp), y = min(data$rain)) +
annotate('text', label = 'bold("Warm and Dry")', size = 3, parse = T,
x = max(data$temp), y = min(data$rain)) +
theme_bw() +
theme(
plot.background = element_blank()
,panel.grid.major = element_blank()
,panel.grid.minor = element_blank()
)
labs(x = 'Average Temperature (°C)',
y = 'Cumulative precipitation (mm)')+ theme_light()
library(ggplot2)
setwd('C:/Users/nchatterjee2/Desktop')
data <- read.csv("Fall.csv", header=TRUE, sep=",",row.names=NULL, fill = T)
limit_humid <- 128
limit_warm <- 11
head(data)
ggplot(data, aes(x = temp, y = rain)) +
geom_text(aes(label = Year))+
geom_vline(xintercept = limit_warm) +
geom_hline(yintercept = limit_humid) +
annotate('text', label = 'bold("Cool and Wet")', size = 3, parse = T,
x = min(data$temp), y = max(data$rain)) +
annotate('text', label = 'bold("Warm and Wet")', size = 3, parse = T,
x = max(data$temp), y = max(data$rain)) +
annotate('text', label = 'bold("Cool and Dry")', size = 3, parse = T,
x = min(data$temp), y = min(data$rain)) +
annotate('text', label = 'bold("Warm and Dry")', size = 3, parse = T,
x = max(data$temp), y = min(data$rain)) +
theme_bw() +
theme(
plot.background = element_blank()
,panel.grid.major = element_blank()
,panel.grid.minor = element_blank()
)
labs(x = 'Average Temperature (°C)',
y = 'Cumulative precipitation (mm)')+ theme_light()
【问题讨论】: