【问题标题】:Plot histograms or pie charts in a scatter plot在散点图中绘制直方图或饼图
【发布时间】:2016-10-09 22:16:05
【问题描述】:

我需要重复做的事情: tiny pie charts to represent each point in an scatterplot using ggplot2 但我偶然发现包 ggsubplot 不适用于 3.3.1 R 版本的问题。

基本上我需要散点图上预定义点的直方图或饼图。以下是引用帖子中使用的相同代码:

foo <- data.frame(X=runif(30),Y=runif(30),A=runif(30),B=runif(30),C=runif(30))
foo.m <- melt(foo, id.vars=c("X","Y"))
ggplot(foo.m, aes(X,Y))+geom_point()
ggplot(foo.m) +
    geom_subplot2d(aes(x = X, y = Y, subplot = geom_bar(aes(variable, 
value, fill = variable), stat = "identity")), width = rel(.5), ref = NULL)

代码用到了reshape2、ggplot2和ggsubplot库。

我想看的图片是in the post cited above

UPD:我下载了旧版本的 R(3.0.2 和 3.0.3)和检查点包,并使用:

checkpoint("2014-09-18")

如以下评论中所述。但我得到一个错误:

Using binwidth 0.0946
Using binwidth 0.0554
Error in layout_base(data, vars, drop = drop) : 
At least one layer must contain all variables used for facetting

我无法解决,因为当我尝试包含构面时,会出现以下错误:

Error: ggsubplots do not support facetting

【问题讨论】:

    标签: r ggplot2 histogram pie-chart scatter-plot


    【解决方案1】:

    看起来ggsubplot 不会很快自我修复。一种选择是使用checkpoint package,基本上将您的R 副本“重置”到包兼容的时间。 This post 建议使用 2014-09-18 的时间点。

    【讨论】:

    • 谢谢!我安装了 r 版本 3.0.2 和检查点包,以及代码所需的所有包。我运行了代码,出现以下错误: Using binwidth 0.0946 Using binwidth 0.0554 Error in layout_base(data, vars, drop = drop) : 至少一层必须包含用于分面的所有变量你碰巧知道这个错误是什么是什么意思?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-28
    • 1970-01-01
    • 1970-01-01
    • 2018-01-30
    • 2013-08-21
    相关资源
    最近更新 更多