Change the X-axis scale

Asked

Viewed 13,721 times

2

Hello, I’m trying to make a chart of thinning the trunk of a tree, where the y axis is the height (meters) and the x axis is the diameter (cm). So far no problem, but I would like to change the x-axis scale to give more realism and I’m not able to do it, someone would have some suggestion ?

  • What you call changing the x-axis scale, turn from cm to meters for example?

2 answers

6

If you are using basic R commands to chart (plot()), you can change the x/y axis with the parameter xlim/ylim

x <- rnorm(100, 10, 2)
y <- rnorm(100, 100, 20)
plot(x, y)
plot(x, y, xlim = c(0, 120)) # Alterando somente o eixo X
plot(x, y, ylim = c(0, 120)) # Alterando somente o eixo Y
plot(x, y, xlim = c(0, 120), ylim = c(0, 120)) # Alterando os 2 eixos
  • Thanks for the suggestion, but I had tried to do that.. It even does what I want the problem is that the x or y axis is too long and useless in empty space..

  • 1

    @Marcomachado What do you want then? Edit your question to make the problem clearer if this is not the solution you are looking for.

0

I followed this tutorial, which shows how to configure the axes in a well didactic way.

But in short, explaining with my words and the way I used in my case (I’m beginner in R), I did so:

# axes=F -> retira os eixos do seu gráfico.
plot("seus dados", ..., axes=F)

# A função axis permite configurar os eixos, sendo "1"
# indicativo do eixo "abaixo" do gráfico (o eixo "x")
# e o parâmetro "at" indica que valores devem aparecer
# no eixo. Da mesma forma para o eixo vertical.
axis(1,at=c(x1,x2,x3,...,xn)

# "2" indica o eixo y (à esquerda do gráfico)
# e pelo "at" seus respectivos valores.
axis(2,at=c(y1,y2,y2,...,yn))

Browser other questions tagged

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