我尝试以#34; Month-Year"格式标记线图的x轴。
library(ggplot2)
library(directlabels)
library(grid)
library(tidyr)
library(RColorBrewer)
library(scales)
library(scales)
Listings100$Year<- as.Date(Listings100$Year)
p100 <- ggplot(Listings100, aes(x=Year, y=Listings, group=Neighborhood,
colour=Neighborhood)) + geom_line() +
labs(x = "", y = "Number of listings")+
scale_color_brewer(palette="Set1") +
scale_x_date(labels = date_format("%b-%Y")) +
geom_line(size=1.1)
然而,当绘制这个时,x轴表示&#34; 1月 - 年&#34;虽然它实际应该是&#34;五月 - 一年&#34;。有关月份标签错误的任何想法吗?
数据
structure(list(Year = structure(c(1273017600, 1304553600, 1336176000,
1367712000, 1399248000, 1430784000, 1462406400, 1493942400, 1273017600,
1304553600, 1336176000, 1367712000, 1399248000, 1430784000, 1462406400,
1493942400), class = c("POSIXct", "POSIXt"), tzone = "UTC"),
Neighborhood = c("A", "A", "A", "A", "A", "A", "A", "A",
"B", "B", "B", "B", "B", "B", "B", "B"), Cluster = c(100,
100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
100, 100, 100), Listings = c(0, 0, 4, 10, 11, 30, 15, 6,
3, 8, 10, 16, 19, 51, 25, 42)), .Names = c("Year", "Neighborhood",
"Cluster", "Listings"), class = c("tbl_df", "tbl", "data.frame"
), row.names = c(NA, -16L))