r - 带有两个变量的点图
问题描述
df <- data.frame(a=c(227, 222, 218, 216, 218, 217, 225, 229, 228, 221)
,b=c(219, 214, 218, 203, 215, 211, 209, 204, 201, 205))
library(ggplot2)
ggplot(df,aes(a, b))+geom_dotplot()
我想用不同的标记来表示 a 和 b 组。
解决方案
我们需要重塑为“长”格式
library(dplyr)
library(tidyr)
library(ggplot2)
df %>%
pivot_longer(cols = everything()) %>%
ggplot(aes(x = value, color = name, fill = name)) +
geom_dotplot()
推荐阅读
- php - 如何避免在php中的每个请求都连接到mysql数据库?
- javascript - Typescript 使用导入编译
- asp.net-core - 如何在 dotnet core 上读取 Windows 环境变量?
- garbage-collection - 应用程序在 G1GC 的备注阶段需要更多时间来处理 JNI 弱引用
- python - 如何在python中使用最小化来拟合数据和方程以获得模型参数
- r - 如何匹配 R 中两个变量的数据?
- sql - 尝试创建触发器
- java - 从另一个访问一个 jar 文件时出现问题
- laravel - 如何让 vue 组件等到数据准备好渲染?
- rtf - Apache Tika:无法使用 {\*\objclass Outlook.FileAttach} 从 RTF 文件中提取嵌入对象