You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I make an empirical probability mass functions (pmf), I like to use linerange with ymin=0 and ymax equal to the value of the empirical pmf. stat_count works well but I cannot use linerange with it without using kind of weird hack.
library(ggplot2)
# works and gives a bar chart
ggplot(mtcars,aes(x=gear))+stat_count()
# throws an error
ggplot(mtcars,aes(x=gear))+stat_count(aes(ymax=..prop..,ymin=0),geom="linerange")
# Error: stat_count() must not be used with a y aesthetic.# this works because it does not populate the ymin variable
ggplot(mtcars,aes(x=gear))+stat_count(aes(ymax=..prop..,ymin=..prop..-..prop..),geom="linerange")
The reason that it fails is because when I set ymin=0 in aes, the data variable has a column with name ymin and is.null(data$y) returns true which results in the error. The hack involves setting ymin=..prop..-..prop.. in the aes call.
Yes there are definitely some workarounds and not sure if this is really a bug but it is somewhat weird (though very R) behavior. To me, the width solution is less appealing than theymin=..prop..-..prop.. solution.
Otherwise, given that there are other ways to solve the problem (i.e. counting yourself) and it affects few people, I unfortunately don't have the time to make a fix.
When I make an empirical probability mass functions (pmf), I like to use linerange with ymin=0 and ymax equal to the value of the empirical pmf. stat_count works well but I cannot use linerange with it without using kind of weird hack.
The reason that it fails is because when I set
ymin=0
inaes
, the data variable has a column with nameymin
andis.null(data$y)
returns true which results in the error. The hack involves settingymin=..prop..-..prop..
in theaes
call.ggplot2/R/stat-count.r
Line 53 in c592e32
The text was updated successfully, but these errors were encountered: