首页 > 解决方案 > 使用ggplot和melt函数

问题描述

我正在遵循下面列出的示例(https://rpubs.com/thinh_ha/londonhouseprice)。我正在尝试按部分使用该组。

 by_pt <- select(df, realprice1, class) %>%
  group_by(class) %>%
  summarise(Count=n(), Mean.Price=mean(realprice1), St.Dev.Price=sd(realprice1), Median.Price=median(realprice1))


ggplot(melt(by_pt), aes(x=value, y=variable, fill=class)) +
  facet_wrap(~ variable, scales='free') +
  geom_bar(position="dodge", stat='identity', width=0.3)

我的代码的第一部分创建了一个名为 by_pt 的数据框,它有两行和 5 列。第一列是类,第一列是 Sole 和 Second Joint。其余四个是在汇总函数中创建的统计信息。

但是,当我使用 ggplot 时,出现以下错误。

使用类作为 id 变量 match.names(clabs, names(xi)) 中的错误:名称与以前的名称不匹配

谁能解释为什么会这样?

标签: rggplot2melt

解决方案


推荐阅读