0

People, please can you evaluate my code and give me a hand?

I need to reverse de X-axis of my box-plot, as you can see, the x-axis is the age in Ma, R plot the values in ascending range and I need them in the reverse form (ie 65-64, 64 -63, 63-62, 62-61, 61-60). I tried with scale_y_reverse (), but no good results

Please help me.

Thanks a lot.Box-plot

Install Tidiverse install.packages("tidyverse")

Open library

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)')

4

1 回答 1

0

一个潜在的解决方案是使用forcats 包fct_rev()(tidyverse 的一部分)中的函数,例如,使用palmerpenguins 包中的示例数据集:

# 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)')

示例_1.png

并且,使用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)')

示例_2.png

该解决方案依赖于“物种”作为一个因素。在您的数据集中,等效变量是“EDAD_1”。如果“EDAD_1”不是一个因子,在绘制数据之前,将其更改为一个因子:

Filogen$EDAD_1 <- factor(Filogen$EDAD_1)
于 2021-06-17T00:32:56.243 回答