Reputation: 413
So I have a plot where I want the x-axis to show specific dates starting at the 16-06-2016 through to the 04-08-2016, with week dates labeled on the x-axis. This so far I have managed to do - however, I would also like there to be blank tick marks per day, as well as the week labels - but I am not sure I can apply multiple scale_x_date(breaks =) conditions.
Any help on how to add the additional tick marks would be appreciated!
Dummy data set to play with:
library(ggplot2)
library(reshape2)
#some data
df <- structure(list(Date = structure(c(16968, 16969, 16970, 16971,
16972, 16973, 16974, 16975, 16976, 16977, 16978, 16979, 16980,
16981, 16982, 16983, 16984, 16985, 16986, 16987, 16988, 16989,
16990, 16991, 16992, 16993, 16994, 16995, 16996, 16997, 16998,
16999, 17000, 17001, 17002, 17003, 17004, 17005, 17006, 17007,
17008, 17009, 17010, 17011, 17012, 17013, 17014, 17015, 17016
), class = "Date"), Tc = c("0.0964", "0.0780", "0.1265", "0.1503",
"0.1548", "0.1028", "0.1112", "0.1283", "0.0956", "0.0847", "0.0785",
"0.0859", "0.0879", "0.1203", "0.1677", "0.2174", "", "", "0.1496",
"0.1080", "0.1101", "0.1289", "0.0942", "0.0835", "0.0851", "0.0881",
"0.1216", "0.0766", "0.0744", "0.0626", "", "0.1116", "", "0.0862",
"", "0.1210", "", "", "0.1074", "", "0.1527", "", "0.1513", "",
"0.1246", "", "0.1415", "", "0.0827")), .Names = c("Date", "Tc"
), class = "data.frame", row.names = 3:51)
# melt data frame
df <- melt(df, id.vars = c("Date"))
#basic plot
plot1 <- ggplot(df[!is.na(df$value), ],
aes(x=Date, y=value, color=variable, group = variable,shape
= variable, linetype = variable, fill = variable))
# points
plot1 <- plot1 + geom_line(lwd =3)+geom_point(size=17, stroke =2)
break.vec <- c(as.Date("2016-06-16"),
seq(from=as.Date("2016-06-16"), to=as.Date("2016-08-04"),
by="week"))
plot1 <- plot1 + scale_x_date(breaks = break.vec, date_labels = "%d-%m", limits=range(break.vec))
Upvotes: 0
Views: 326
Reputation: 413
Ok thank you for the input! This is what I went with from the comments, although I am sure there might be a more concise way to do so - but it does the job!
break.vec <- seq(from=as.Date("2016-06-16"), to=as.Date("2016-08-04"),
by="day")
plot1 <- plot1 + scale_x_date(breaks = break.vec,
labels=c("16-06","","","","","","","23-06","","","","","","", "30-06",
"","","","","","", "07-07", "","","","","","", "14-07",
"","","","","","","21-07", "","","","","","", "28-07",
"","","","","","", "04-08"),expand = c(0.05,0))
Upvotes: 1