Does qplot with stat=identity argument exist in the syntax? Checked the documentation but couldn't find

Viewed 39

R graphics cook book winston chang page 12 gives the syntax given below that does not work

library(ggplot2)
qplot(BOD$Time, BOD$demand, geom="bar", stat="identity")
# Convert the x variable to a factor, so that it is treated as discrete
qplot(factor(BOD$Time), BOD$demand, geom="bar", stat="identity")

Error:

Error: stat_count() can only have an x or y aesthetic. Run rlang::last_error() to see where the error occurred. In addition: Warning message: stat is deprecated

I know that ggplot has geom_bar with stat=identity, just checking if qplot has as i dont see in the documentation

1 Answers

?geom_bar

There are two types of bar charts: geom_bar() and geom_col(). geom_bar() makes the height of the bar proportional to the number of cases in each group (or if the weight aesthetic is supplied, the sum of the weights). If you want the heights of the bars to represent values in the data, use geom_col() instead. geom_bar() uses stat_count() by default: it counts the number of cases at each x position. geom_col() uses stat_identity(): it leaves the data as is.

When making a bar chart, only specify x or y. Switch to column col chart to use both.

qplot(BOD$Time, BOD$demand, geom="col")

Related