Reputation: 73
I have written the following plot command:
Stripped_DATA <- structure(list(Epoch = structure(c(1110925802, 1110929408, 1110933014,
1110936616, 1110940217),
class = c("POSIXct", "POSIXt"),
tzone = "Europe/Helsinki"),
Timediff = c(-1.4653909261659, -1.46512243581845,
-1.46505141447328, -1.46503418192427, -1.46464648029912)),
.Names = c("Epoch", "Timediff"),
row.names = c("11070", "21070", "31070", "41070", "51070"),
class = "data.frame")
plot(Stripped_DATA, main = "Maser-69 hourly averages raw data, -3 < 3 microseconds", xlab = "Date", ylab = "microseconds")
ticks <- seq(as.POSIXct("2005-03-16 00:30:02", format = "%F %T"),
as.POSIXct("2019-04-19 14:29:55", format = "%F %T"), by = "4 months")
labels <- seq(as.Date("2005-03-16"), as.Date("2019-04-19"), by = "4 months")
axis.POSIXct(1, at = ticks, format = "%Y-%m-%d %H", labels = labels)
which gives the x-axis shown in the plot. How do I eliminate the three yearly ticks which overlap the dates? Also, is there a way to turn the date labels from horizontal to vertical so I can add more date labels?
Upvotes: 3
Views: 560
Reputation: 2956
If you just want to use your ticks, remove the labels from your plot before plotting it with xaxt='n'
and rotate your plot labels with las=2
plot(Stripped_DATA, main = "Maser-69 hourly averages raw data, -3 < 3 microseconds",
xlab = "Date", ylab = "microseconds" , las=2, xaxt="n")
ticks <- seq(as.POSIXct("2005-03-16 00:30:02", format = "%F %T"),
as.POSIXct("2019-04-19 14:29:55", format = "%F %T"), by = "4 months")
labels <- seq(as.Date("2005-03-16"), as.Date("2019-04-19"), by = "4 months")
axis.POSIXct(1, at = ticks, format = "%Y-%m-%d %H", labels = labels, las=2)
explanation: your axis.POSIct()
function adds additional labels. Those can overlap with your plot labels and create your shown output. So don't plot the original labels with xaxt='n'
Be aware this is just IF you only want to have your axis.POSIXct
labels
Upvotes: 1
Reputation: 1599
Using your data provided in the comments. Note the comment from mischva11 and the link below.
Rotating x axis labels in R for barplot
Only the las = 2
argument in theplot
function is required.
Stripped_DATA <- structure(list(Epoch = structure(c(1110925802, 1110929408, 1110933014,
1110936616, 1110940217),
class = c("POSIXct", "POSIXt"),
tzone = "Europe/Helsinki"),
Timediff = c(-1.4653909261659, -1.46512243581845,
-1.46505141447328, -1.46503418192427,
-1.46464648029912)),
.Names = c("Epoch", "Timediff"), row.names = c("11070", "21070",
"31070", "41070",
"51070"),
class = "data.frame")
plot(Stripped_DATA, main = "Maser-69 hourly averages raw data, -3 < 3 microseconds",
xlab = "Date", ylab = "microseconds",
las = 2) # see
ticks <- seq(as.POSIXct("2005-03-16 00:30:02", format = "%F %T"),
as.POSIXct("2019-04-19 14:29:55", format = "%F %T"), by = "4 months")
labels <- seq(as.Date("2005-03-16"), as.Date("2019-04-19"), by = "4 months")
axis.POSIXct(1, at = ticks, format = "%Y-%m-%d %H", labels = labels)
Upvotes: 1