开发者

Barplot Error in R using ggplot

I try to make a barplot of a time-series dataset with ggplot2 but I get following error message (I have performed this on a similar dataset and it works):

Error in if (!is.null(data$ymin) && !all(data$ymin == 0)) warning("Stacking not we开发者_如何学运维ll defined when ymin != 0",  : missing value where TRUE/FALSE needed

For this I have used following code:

p <- ggplot(dataset, aes(x=date, y=value)) + geom_bar(stat="identity")

If I use geom_point() instead of geom_bar() it works fine.


You haven't provided a reproducible example, so I'm just guessing, but your syntax doesn't look right to me. Check here: http://docs.ggplot2.org/current/geom_bar.html

Bar charts by default produce tabulations of counts:

p <- ggplot( dataset, aes( factor(date) ) ) + geom_bar()

If you want it to do something different, you'll need to tell it what statistic to use. See the link above (towards the bottom) for an example using the mean. Alternatively, see here for a hybrid point/scatterplot (very bottom of the page): http://docs.ggplot2.org/current/position_jitter.html

But fundamentally you have two continuous variables and it's not clear to me why you'd want anything but a scatterplot.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜