如何在箱线图中反转x轴
How to reverse x-axis in box-plot
亲们,请您评估一下我的代码并帮帮我好吗?
我需要反转箱线图的 X 轴,如您所见,X 轴是 Ma 中的年龄,R 绘制升序范围内的值,我需要它们的反转形式 (即 65-64、64 -63、63-62、62-61、61-60)。我试过用scale_y_reverse(),但没有好的结果
请帮助我。
非常感谢。Box-plot
安装 Tidiverse
install.packages("tidyverse")
打开图书馆
library(tidyverse)
Usign qplot
qplot(data =Filogen, x = Filogen$EDAD_1, y = Filogen$AREA_SUR, fill = Filogen$EDAD_1, geom = "boxplot", ylab = 'Área (km²)', xlab = 'Edad (Ma)')
一个潜在的解决方案是使用 forcats package (part of the tidyverse), for instance, using the example dataset from the palmerpenguins package:
中的 fct_rev()
函数
# Load libraries
library(tidyverse)
library(palmerpenguins)
# Create a minimal reproducible example
MRE <- penguins %>%
na.omit()
# Plot the penguins data
qplot(data = MRE, x = species, y = bill_length_mm, fill = species, geom = "boxplot", ylab = 'Área (km²)', xlab = 'Edad (Ma)')
并且,使用 fct_rev()
:
# Load libraries
library(tidyverse)
library(palmerpenguins)
# Create a minimal reproducible example
MRE <- penguins %>%
na.omit()
# Plot the penguins data
qplot(data = MRE, x = fct_rev(species), y = bill_length_mm, fill = species, geom = "boxplot", ylab = 'Área (km²)', xlab = 'Edad (Ma)')
这个解决方案依赖于“物种”作为一个因素。在您的数据集中,等效变量是“EDAD_1”。如果“EDAD_1”不是一个因素,在绘制数据之前,将其更改为一个因素:
Filogen$EDAD_1 <- factor(Filogen$EDAD_1)
亲们,请您评估一下我的代码并帮帮我好吗?
我需要反转箱线图的 X 轴,如您所见,X 轴是 Ma 中的年龄,R 绘制升序范围内的值,我需要它们的反转形式 (即 65-64、64 -63、63-62、62-61、61-60)。我试过用scale_y_reverse(),但没有好的结果
请帮助我。
非常感谢。Box-plot
安装 Tidiverse
install.packages("tidyverse")
打开图书馆
library(tidyverse)
Usign qplot
qplot(data =Filogen, x = Filogen$EDAD_1, y = Filogen$AREA_SUR, fill = Filogen$EDAD_1, geom = "boxplot", ylab = 'Área (km²)', xlab = 'Edad (Ma)')
一个潜在的解决方案是使用 forcats package (part of the tidyverse), for instance, using the example dataset from the palmerpenguins package:
中的fct_rev()
函数
# Load libraries
library(tidyverse)
library(palmerpenguins)
# Create a minimal reproducible example
MRE <- penguins %>%
na.omit()
# Plot the penguins data
qplot(data = MRE, x = species, y = bill_length_mm, fill = species, geom = "boxplot", ylab = 'Área (km²)', xlab = 'Edad (Ma)')
并且,使用 fct_rev()
:
# Load libraries
library(tidyverse)
library(palmerpenguins)
# Create a minimal reproducible example
MRE <- penguins %>%
na.omit()
# Plot the penguins data
qplot(data = MRE, x = fct_rev(species), y = bill_length_mm, fill = species, geom = "boxplot", ylab = 'Área (km²)', xlab = 'Edad (Ma)')
这个解决方案依赖于“物种”作为一个因素。在您的数据集中,等效变量是“EDAD_1”。如果“EDAD_1”不是一个因素,在绘制数据之前,将其更改为一个因素:
Filogen$EDAD_1 <- factor(Filogen$EDAD_1)