r - 需要使用 data.frame 中的两列数据制作条形图
问题描述
我正在尝试从 data.frame 中并排制作两列的条形图。我努力了:
barplot(data.frame$data1, data.frame$data2, data=data.frame)
here is data:
Neutral Emotional
1 0.790 1.6400
2 0.051 0.0880
3 0.891 2.7200
4 0.430 1.1800
5 -0.009 -0.6000
但它会产生大量的酒吧,而不仅仅是两个。我试图有两个条,一个带有中性条,一个带有代表 SEM 的情感条和误差条。
解决方案
一个选项是gather
进入“长”格式,然后使用geom_bar
fromggplot2
library(tidyverse)
library(ggplot2)
gather(df1) %>%
ggplot(., aes(x = key, y = value)) +
geom_bar(stat = 'identity')
如果我们还需要一个错误栏,那么
gather(df1) %>%
ggplot(., aes(x = key, y = value)) +
stat_summary(fun.y = mean, geom = "bar") +
stat_summary(fun.data = mean_se, geom = "errorbar")
数据
df1 <- structure(list(Neutral = c(0.79, 0.051, 0.891, 0.43), Emotional = c(1.64,
0.088, 2.72, 1.18)), class = "data.frame", row.names = c("1",
"2", "3", "4"))
推荐阅读
- javascript - 通过 C# 添加 attirubtes 时 HTML5 ondragstart 不会触发
- gspread - 如何将大量表中的数据添加到一张表中
- python - 慢速迭代的替代方案
- sql - TypeError:无法读取反应原生 sqlite 中未定义的属性“打开”
- php - 如何在PHP的while循环中分离输出的复选框变量结果?
- haskell - 序列号的建设性处理
- android - 如果它的适配器使用对由单独类管理的 MutableListView 的引用,我真的需要 DiffUtil.ItemCallback 来更新我的 RecyclerView 吗?
- java - 我们可以在不运行单独的 ignite 集群的情况下将 Apache ignite 与 Spring 应用程序一起使用吗
- ios - PKPaymentAuthorizationViewController 不调用委托
- python - 用于安装 pandas 的 Sagemaker 生命周期配置不起作用