【发布时间】:2019-08-28 05:45:03
【问题描述】:
我正在使用分面网格来生成我的数据的简洁表示。 基本上,我的数据框有四列:
idx、密度、标记、大小写。
有5个case,每个case对应5个marker,每个marker对应多个idx,每个idx对应一个密度。
数据上传到这里: data frame link
我尝试使用 facet_grid 来实现我的目标,但是,我得到了一个非常混乱的图表:
x轴和y轴打乱了,代码是:
library(ggplot2)
library(cowplot)
plot.density <-
ggplot(df_densityWindow, aes(x = idx, y = density)) +
geom_col() +
facet_grid(marker ~ case, scales = 'free') +
background_grid(major = 'y', minor = "none") + # add thin horizontal lines
panel_border() # and a border around each panel
plot(plot.density)
编辑:
我重新上传了文件,现在它应该可以工作了: download file here
【问题讨论】:
-
你能显示
str(df_densityWindow)吗? x 和 y 是某种因素吗? -
坐标轴表示您的输入变量
ids和density被读取为不同的分类值,而不是连续数据。所以ggplot尝试标记每个变量。正如其他评论员所评论的那样显示您的数据框的结构,但我怀疑这个问题部分与您加载数据的方式有关。此外,您链接到的文件在我的计算机上是空的。 -
@MrGumble 感谢您的评论!我添加了一个新链接,现在应该可以使用了!
标签: r ggplot2 facet-wrap facet-grid