I'd like to plot some data histogram-style. The data is scaled so that one single observation has a value of 100. However, the data will be broken up by category into separate sections of a document, so the maximum value of most groups will not be 100.
I'd like my plots to use a log10 y axis, and to have use a fixed 0 to 100 scale.
The following honors the log transformation, but ignores the 0-100 range with a warning. I have tried other permutations of coord_cartesian(ylim = c(0, 100)) and scale_y_continuous(trans = log10_trans()), with no luck yet.
library(ggplot2)
toread <- "general specific satisfaction
fruit apple 9
fruit apple 8
fruit banana 8
fruit banana 7
fruit pear 6
veg carrot 7
veg celery 4
veg turnip 3
veg turnip 2
veg turnip 1
grain pasta 6
grain quinoa 3
grain brownrice 2
grain brownrice 6"
foodprefs <- read.table(textConnection(toread), header = TRUE)
closeAllConnections()
foodprefs$pct.max <- (foodprefs$satisfaction / max(foodprefs$satisfaction)) * 100
lapply(sort(unique(
as.character(foodprefs$general))), function(one.cat) {
temp <- foodprefs[foodprefs$general == one.cat , ]
ggplot(temp, aes(x = specific, y = pct.max)) +
geom_boxplot() +
ylim(0, 100) +
scale_y_log10() +
coord_flip()
})