How do I place the inverted (decreasing) Y-axis in the R?

Asked

Viewed 1,588 times

6

I’m trying to present some graphs on uniformity coefficient, but normally in this type of graph, the Y-axis is organized in descending order, from 100 to 0.

I would like to know how do I perform this procedure. It may be for the function plot and/or for the function xyplot of the Lattice package.

cuc <- c(11.37,11.38,11.44,11.47,11.29,11.10,
11.29,11.40,11.45,11.35,10.53,10.39,
10.12,10.25,10.04,9.93,9.92,9.97,
10.91,9.29,8.67,9.40,10.14,11.36,
10.44,9.62,9.68,10.41,11.22,11.43,
10.12,9.81,7.28,10.45,11.16,11.16,
10.39,10.70,11.40,11.44,11.23,10.71,
11.52,11.36,11.43,11.49,11.27,11.38,
11.55,11.84,11.40,11.42,11.25,11.41)

foot <- length(cuc)

X <- seq(((1/foot)*100)/2,100,(100/foot))

plot(cuc~X, type="l", lwd=2)

require(lattice)

xyplot(cuc~X, type="l", lwd=2,col=1)

Chart example

inserir a descrição da imagem aqui

2 answers

5


Simple, reverse the answer and then customize the shafts!

Examples with your data:

## Dados
cuc <- c(11.37, 11.38, 11.44, 11.47, 11.29, 11.1, 11.29, 11.4,
         11.45, 11.35, 10.53, 10.39, 10.12, 10.25, 10.04, 9.93,
         9.92, 9.97, 10.91, 9.29, 8.67, 9.4, 10.14, 11.36,
         10.44, 9.62, 9.68, 10.41, 11.22, 11.43, 10.12, 9.81,
         7.28, 10.45, 11.16, 11.16, 10.39, 10.7, 11.4, 11.44,
         11.23, 10.71, 11.52, 11.36, 11.43, 11.49, 11.27, 11.38,
         11.55, 11.84, 11.4, 11.42, 11.25, 11.41)
foot <- length(cuc)
X <- seq(((1/foot) * 100)/2, 100, (100/foot))
##-------------------------------------------

## Com graphics
plot(-cuc ~ X, type = "l", lwd = 2, axes = FALSE)
axis(3)
axis(2, at = -pretty(cuc), labels = pretty(cuc))

## Com lattice
library(lattice)
xyplot(-cuc ~ X, type = c("l", "g"),
       lwd = 2, col = 1,
       scales = list(
           x = list(alternating = 2),
           y = list(at = -pretty(cuc), labels = pretty(cuc)))
       )

## Com plotrix
library(plotrix)
revaxis(x = X, y = cuc, type = "l")

5

Just reverse the order of the argument ylim inside the command plot. Normally, it makes the axis go from minimum to maximum of the response variable. In your case, do the ylim vary from maximum to minimum.

cuc <- c(11.37,11.38,11.44,11.47,11.29,11.10,
         11.29,11.40,11.45,11.35,10.53,10.39,
         10.12,10.25,10.04,9.93,9.92,9.97,
         10.91,9.29,8.67,9.40,10.14,11.36,
         10.44,9.62,9.68,10.41,11.22,11.43,
         10.12,9.81,7.28,10.45,11.16,11.16,
         10.39,10.70,11.40,11.44,11.23,10.71,
         11.52,11.36,11.43,11.49,11.27,11.38,
         11.55,11.84,11.40,11.42,11.25,11.41)

foot <- length(cuc)

X <- seq(((1/foot)*100)/2,100,(100/foot))

par(mfrow=c(1,2))
plot(cuc~X, type="l", lwd=2, main="Eixo Tradicional")
plot(cuc~X, type="l", lwd=2, ylim=c(max(cuc), min(cuc)), main="Eixo Invertido")

Resultado do exemplo

Browser other questions tagged

You are not signed in. Login or sign up in order to post.