Ok, this is kind of an odd one. I was answering a question for a beginner around geom_histogram
, and the OP posted an example using backticks. He neglected to add data so I made it up, and then found an answer, not even noticing the backticks. But another (actually more elegant) answer was posted without backticks. It did not really work, but it worked a lot better with the backticks.
But now I am puzzled. I don't see why there should have been a difference at all. Even the ggplot list is almost identical, only the ggplot$mapping
element is different as far as I can see (ok, that is a biggie). I have googled about, but I don't see what is going on.
So here is the code:
This (quotes around Log Number
in aes
):
#Generate some data
lon <- log(rnorm(1000, exp(6)))
state <- sample(c("c", "l", "t"), 1000, replace = T)
d <- data.frame(lon, state)
names(d) <- c("Log Number", "state")
# Plot it
gpsq <- ggplot(d, aes(x = 'Log Number', fill = state)) + geom_histogram()
print(gpsq)
yields this:
But this (backticks around Log Number
in aes
):
#Generate some data
lon <- log(rnorm(1000, exp(6)))
state <- sample(c("c", "l", "t"), 1000, replace = T)
d <- data.frame(lon, state)
names(d) <- c("Log Number", "state")
# Plot it
gpsq <- ggplot(d, aes(x = `Log Number`, fill = state)) + geom_histogram()
print(gpsq)
more correctly yields this:
See Question&Answers more detail:os