r - 如何使用 ggplot2 更改刻面比例?
问题描述
我正在尝试更改某些面板的比例以获得更好的视图。facet_grid
但是,在scales
are already"free"
中,我需要与第一个范围相对应的行使用不同的比例。有谁知道如何做到这一点?
library (ggplot2)
Source <- c(rep("Water", 12), rep("Oil", 12))
Range <- rep((c(rep("First", 4), rep("Second", 8))),2)
Xaxis <- c(0,1,2,5,0,1,2,5,10,20,30,40,
0,1,2,5,0,1,2,5,10,20,30,40)
Yaxis <- c(0,1,2,5,0,1,2,5,10,20,30,40,
0,1,2,5,0,1,2,5,10,20,30,40)
DF <- data.frame(Source, Range, Xaxis, Yaxis)
ggplot(data = DF, aes(x = Xaxis, y = Yaxis)) +
geom_smooth(method = "lm") +
geom_point() +
facet_grid(Range~Source,
scales = "free")
我希望前排看起来像这样:
解决方案
另一种方法是使用,facet_wrap()
而不是facet_grid()
,例如
library(tidyverse)
Source <- c(rep("Water", 12), rep("Oil", 12))
Range <- rep((c(rep("First", 4), rep("Second", 8))),2)
Xaxis <- c(0,1,2,5,0,1,2,5,10,20,30,40,
0,1,2,5,0,1,2,5,10,20,30,40)
Yaxis <- c(0,1,2,5,0,1,2,5,10,20,30,40,
0,1,2,5,0,1,2,5,10,20,30,40)
DF <- data.frame(Source, Range, Xaxis, Yaxis)
ggplot(data = DF, aes(x = Xaxis, y = Yaxis)) +
geom_smooth(method = "lm") +
geom_point() +
facet_wrap(Range~Source,
scales = "free")
推荐阅读
- node.js - React:使用 Next.js 上传损坏的分块文件
- java - 如何存储我从上一个屏幕获得的 lastid 并获取该 id 并单击下一个选项卡中的 id
- mysql - 提高 SQL 性能:多次插入或更新多个表
- pyspark - pyspark collect_list() 和 collect_set() 使用 groupByKey 还是使用 reduceByKey?
- git - 如何使用“git checkout -d”?
- groovy - groovy中的转置列表
- postgresql - PostgreSQL:从选择中插入的一些麻烦与冲突
- python - 序列化 Django RawQuery 的推荐方式
- java - 获取 :: java.lang.NoSuchMethodError: org.apache.xmlbeans.XmlOptions.put(Ljava/lang/Object;)V
- macos - 在钥匙串 MacOS 中找不到 github