ggplot中的错误在R中 [英] Error in ggplot In R
问题描述
continuous_scale中出现错误(美学,日期,身份,休息=休息,
未使用参数(格式=%b-%Y)
语法:
ggplot(p29,aes(dt,ambtemp)) + geom_line()+
scale_x_date(format =%b-%Y)+ xlab()+ ylab(Tempreture)
文件名: p29
ambtemp dt surtemp
1 -1.14 2007-09-29 00:01:57 -2.712
2 -1.12 2007-09-29 00:03:57 -2.775
3 -1.33 2007-09-29 00:05:57 -2.712
4 -1.44 2007-09-29 00:07:57 -2.837
5 -1.54 2007-09-29 00:09:57 -2.775
6 -1.29 2007-09-29 00:11:57 -2.900
在函数 scale_x_date()
中,应该写 labels = date_format(%b-%Y)
。另外栏 dt
应该格式化为 Date
。
library scale
p29 $ dt = as.Date(p29 $ dt,format =%Y-%m-%d%H:%M:%S)
ggplot(p29,aes ,ambtemp))+ geom_line()+
scale_x_date(labels = date_format(%b-%Y))+ xlab()+ ylab(Tempreture)
要显示小时和分钟,而不是函数 scale_x_date()
,您应该使用 scale_x_datetime()
并写入 labels = date_format(%H:%M)
。要控制中断参数 breaks = date_breaks()
被使用。另外栏 dt
应格式化为 POSIXt
。
库(scale)
p29 $ dt = strptime(p29 $ dt,%Y-%m-%d%H:%M:%S)
ggplot(p29,aes(dt,ambtemp))+ geom_line()+
scale_x_datetime(breaks = date_breaks(5 min),labels = date_format(%H:%M))+ xlab )+ ylab(Tempreture)
I wanted to plot time series data in R by using ggplot but I have faced with this error:
Error in continuous_scale(aesthetics, "date", identity, breaks = breaks, :
unused argument(s) (format = "%b-%Y")
Syntax:
ggplot(p29, aes(dt, ambtemp)) + geom_line() +
scale_x_date(format = "%b-%Y") + xlab("") + ylab("Tempreture")
File Name: p29
ambtemp dt surtemp
1 -1.14 2007-09-29 00:01:57 -2.712
2 -1.12 2007-09-29 00:03:57 -2.775
3 -1.33 2007-09-29 00:05:57 -2.712
4 -1.44 2007-09-29 00:07:57 -2.837
5 -1.54 2007-09-29 00:09:57 -2.775
6 -1.29 2007-09-29 00:11:57 -2.900
In function scale_x_date()
you should write labels=date_format("%b-%Y")
. Also column dt
should be formatted as Date
.
library(scales)
p29$dt=as.Date(p29$dt, format="%Y-%m-%d %H:%M:%S")
ggplot(p29, aes(dt, ambtemp)) + geom_line() +
scale_x_date(labels=date_format ("%b-%Y")) + xlab("") + ylab("Tempreture")
To show hours and minutes, instead of function scale_x_date()
you should use scale_x_datetime()
and write labels=date_format("%H:%M")
. To control breaks argument breaks=date_breaks()
is used. Also column dt
should be formatted as POSIXt
.
library(scales)
p29$dt=strptime(p29$dt, "%Y-%m-%d %H:%M:%S")
ggplot(p29, aes(dt, ambtemp)) + geom_line() +
scale_x_datetime(breaks = date_breaks("5 min"),labels=date_format("%H:%M")) + xlab("") + ylab("Tempreture")
这篇关于ggplot中的错误在R中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!