ggplot2错误:缺少值,需要TRUE / FALSE。我不知道

问题描述 投票:-1回答:1

我正在Udemy上在线R课,这是线性回归可视化的代码。我从上一条命令中得到了错误消息。网站上有关共享单车的数据:https://www.kaggle.com/c/bike-sharing-demand/data

数据看起来像:enter image description here

bike <- read.csv("train.csv")
library(ggplot2)
bike$datetime <- as.POSIXct(bike$datetime)
pl <- ggplot(bike, aes(datetime, count)) + geom_point(aes(color = temp),alpha = 0.5)
pl
print(pl)
pl + scale_color_continuous(low='#55D8CE',high='#FF6E2E') +theme_bw()
cor(bike[,c('temp','count')])
ggplot(bike,aes(factor(season),count)) + geom_boxplot(aes(color=factor(season))) +theme_bw()
bike$hour <- sapply(bike$datetime,function(x){format(x,"%H")})
library(dplyr)
pl <- ggplot(filter(bike,workingday==1),aes(hour,count)) 
pl <- pl + geom_point()
pl
pl <- pl + scale_color_gradientn(colours = c('dark blue','blue','light blue','light green','yellow','orange','red'))

pl看起来像:enter image description here当我尝试添加颜色时,我从上一条命令得到了错误消息:if(!alpha || all(lab_in [,4] == 1)中的错误){:在需要TRUE / FALSE的地方缺少值

我不知道如何解决问题,有人可以帮助吗?非常感谢。

r ggplot2 linear-regression kaggle
1个回答
0
投票

如果您想在不同的时间添加不同的颜色,可以执行

library(dplyr)
library(ggplot2)

ggplot(filter(bike,workingday==1),aes(hour,count, color = hour)) + geom_point()

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.