r - 使用 ggplot2 geom_point() 绘制二进制(存在/不存在)数据
问题描述
尝试使用 geom_point() ggplot 绘制存在/不存在数据。
Col1 Col2 Col3
Name Case 1
Name Case2 0
Name Case3 1
Name2 Case 1
Name2 Case2 0
Name2 Case3 1
我试过了:
library(ggplot2)
library(dplyr)
plot <- df %>%
ggplot(aes(x=Col2, y=Col1, fill = Col3, size = 7)) +
geom_point() +
theme(axis.text.x = element_text(angle = 90, hjust = .1, vjust=0.5))
解决方案
如果您只是想显示缺席或存在,那么更改 alpha 可能会起作用。
df<- read.table(header=TRUE, text="Col1 Col2 Col3
Name Case 1
Name Case2 0
Name Case3 1
Name2 Case 1
Name2 Case2 0
Name2 Case3 1")
library(ggplot2)
#need to convert col3 from a continuous value to a discrete value.
ggplot(df, aes(x=Col2, y=Col1, alpha = factor(Col3) )) +
geom_point(size = 10) +
theme(axis.text.x = element_text(angle = 90, hjust = .1, vjust=0.5))
另一种选择是使用颜色美学并定义“白色”和另一种颜色的自定义调色板。
推荐阅读
- google-bigquery - Big Query 用户定义函数显着减慢查询速度
- web-scraping - 如何用 Pentaho 解析 HTML 文件?
- c# - 包含不工作的 Lambda 表达式
- ios - 修复了滚动时消失的按钮/单元格
- php - 如何从同一网络上的 iPhone 访问 Mac localhost PHP 服务器上的网站?
- c# - Azure 突然阻止我访问我的数据库
- flask - 为 Dreamhost Flask 应用程序自动创建 tmp/restart.txt
- javascript - 如何从javascript中的url获取id?
- dynamic - 没有 STB_GNU_UNIQUE 的静态链接 stdc++ 在 dlclose 时导致内存泄漏
- powershell - PowerShell脚本查找数字,如果大于发送电子邮件