温度图:FUN中的错误(X [[i]],...):找不到对象'y'

时间:2017-09-02 10:46:01

标签: r plot ggplot2 viridis

我正在尝试绘制温度,同时从以下链接获取代码: https://cran.r-project.org/web/packages/ggjoy/vignettes/gallery.html

enter image description here

这里作者使用y轴作为月轴,但我想使用x轴作为月轴,使用y轴作为温度轴。

可以从以下链接下载数据: https://drive.google.com/file/d/0ByOfjCmqEilLYndpOWJyZXhPVUk/view

代码如下:

enter code here
library(ggjoy)
library(hrbrthemes)
library(viridis)

setwd <- 'C:/Users/Data/'
weather.raw <- read.csv(file="nebraska-2016.csv", header=TRUE, sep=",")
weather.raw$month<-months(as.Date(weather.raw$Date))
weather.raw$months<-
        factor(rev(weather.raw$month),levels=rev(unique(weather.raw$month)))

mins<-min(weather.raw$Min.TemperatureF)
maxs<-max(weather.raw$Max.TemperatureF)

ggplot(weather.raw, aes(x = months , y = Mean.TemperatureF, fill = ..y..)) + 
geom_joy_gradient(scale = 1, rel_min_height = 0.01, gradient_lwd = 1.) +
scale_x_discrete(expand = c(0.01, 0)) +
scale_y_continuous(expand = c(0.01, 0)) +
scale_fill_viridis(name = "Temp. [°C]", option = "C") +
labs(title = 'Temperatures',
subtitle = 'Histogram of Mean Temperatures (°F) - 2016') +
theme_joy(font_size = 13, grid = TRUE) + theme(axis.title.x = element_blank())

它会出现以下错误。

  

FUN中的错误(X [[i]],...):找不到对象'y'

1 个答案:

答案 0 :(得分:2)

library(ggjoy)
library(hrbrthemes)
library(viridis)

weather.raw <- read.csv(file="nebraska-2016.csv", header=TRUE, sep=",")
weather.raw$month <- months(as.Date(weather.raw$CST))
weather.raw$months <- factor(weather.raw$month,levels=unique(weather.raw$month))

weather.raw$Mean.TemperatureF <- (weather.raw$Mean.TemperatureF-32)/1.8

ggplot(weather.raw, aes(x = Mean.TemperatureF, y = months , fill = ..x..)) + 
geom_joy_gradient(aes(x=Mean.TemperatureF), scale = 1, 
                  rel_min_height = 0.01, gradient_lwd = 1.) + 
coord_flip() +
scale_y_discrete(expand = c(0.01, 0)) +
scale_x_continuous(expand = c(0.01, 0)) +
scale_fill_viridis(name = "Temp. [°C]", option = "C") +
labs(title = 'Temperatures',
subtitle = 'Histogram of Mean Temperatures (°C) - 2016') +
theme_joy(font_size = 13, grid = TRUE) + theme(axis.title.x = element_blank())

enter image description here