我想在我的图形中重命名x ticks marks
with name localtime
,即 "POSIXct" "POSIXt"
我的原版localtime
是葡萄牙语,我想重命名为英文
Dez = 十二月
一月 = 一月
Fev = 二月
三月 = 三月
ps:我不能做一个真实的例子来得到类似的情节结果,因为有超过2000个本地时间。
dt = data.table(localtime= as.POSIXct(c("2016-10-24 12:45:06", "2016-10-24 12:46:13", "2016-10-24 12:47:02", "2016-10-24 12:48:27", "2016-10-24 12:52:39", "2016-10-24 12:55:11", "2016-10-30 21:08:02", "2016-10-30 21:18:27", "2016-10-30 21:30:13","2016-10-24 23:27:21", "2016-10-26 06:54:29")),
depth_range = c("shallow", "deep"),
dmean = c(30, 50, 200, 76, 467, 87, 98, 10, 240, 176, 89))
ggplot(dt, aes( x=localtime, xend= localtime, y=0, yend= dmean, color=depth_range))+
geom_segment( size=1)+
scale_colour_manual(name = "Dive category", values = c("grey70", "orangered3")) +
scale_y_reverse()+
xlab("Time")+
ylab ("Dive depth (m)")+
ggtitle("Whale ID 172001_17")+
theme_bw()
我的数据的真实情节
我尝试了一些东西:
scale_x_discrete(labels=c("Dez"="December","Jan"="January", "Fev"="February", "Mar"= "March"))
scale_x_discrete(labels = c("December", "January", "February", "March"))
scale_x_discrete(breaks=c("Dez", "Jan", "Fev", "Mar"),
labels=c("December", "January", "February", "March"))
scale_x_continuous(breaks=c("Dez", "Jan", "Fev", "Mar"),
labels=c("December", "January", "February", "March"))
scale_x_continuous (names= c("December", "January", "February", "March"))
leg2<- c("December", "January", "February", "March")
scale_x_continuous(labels = leg2)
leg2<- c("December", "January", "February", "March")
scale_x_discrete(labels= leg2)
theme(axis.text.x = c("December", "January", "February", "March"))
theme(axis.text.x = element_text("December", "January", "February", "March"))
#I tried too to convert localtime to factor, but the plot didn't work well
ggplot(dt, aes( x=factor(localtime), xend= factor(localtime), y=0, yend= dmean, color=depth_range))+
显示该错误:
错误:
mapped_discrete
对象只能从数字向量创建
我怎样才能解决这个问题??