I'd like to get the tick marks between consumption bars, such as in http://hante.home.xs4all.nl/plugwise_dagoverzicht_281009_2.jpg .
It's more logical to get the consumption between two dates, or two times...
However, I don't see how to do that in R. Anybody?
I do have such an example table, called data:
date nombre delta
2014-02-01 0 0
2014-02-08 120 120
2014-02-15 205 85
2014-02-22 280 75
2014-02-29 350 70
The code I managed so far to write down is:
data$date <- as.POSIXct(data$date, format = "%Y-%m-%d")
data <- data[-2]
barplot(height=data[,2], names=data[,1], las=2)
But the "ticks" are just below the bars... as you can see on http://imgur.com/0WE7ouI .
You didn't provide any code whatsoever. How is your data represented? How are you plotting the bars?
If you are using package lattice
's barchart(..., horizontal=FALSE)
, you can manually provide new axis tickslabels using the argument scales=list(x=list(at=seq_len(numBars+1) - 0.5, labels=yourLabels)))
where numBars
is the number of bins on your x-axis. See ?barchart
.
If you are using the more primitive barplot
, you can draw an offset axis yourself:
mids <- barplot(x, axisnames=FALSE)
axis(1, at = mids - (mids[2]-mids[1])/2, labels = yourLabels)
Either way, obviously you can shift to the right instead by changing offset signs, or add both outside ticks for numBins
+1 labels.
EDIT : With the code+data you added in your edit:
mids <- barplot(height=data[,2], axisnames=FALSE)
axis(1, at = mids - (mids[2]-mids[1])/2, labels = data[,1], las=2)
or eg writing it and adding an end date:
mstep <- (mids[2] - mids[1]) / 2
axis(1, at=c(mids[1] - mstep, mids + mstep), labels=c(data[,1], endDate), las=2)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.