How to leave in a boxplot in R, all x-axis values written in graph?

Asked

Viewed 612 times

1

I’m filling a boxplot type chart on R, but some values it’s omitting. There is only the risquinho in the x axis referring to the boxplot, but the name of that boxplot does not appear. I believe it is due to the amount of boxplots that exist within the chart. Does anyone know how to solve ? I’m filling it up like this:

boxplot(dados$Peso ~ dados$Idade,
        xlab='Times (hours)', ylab='Weight (grams)',
        outline=F)
  • 3

    Hello, only this information makes it difficult to help you, it is necessary to provide a sample of your data set to understand the problem. Edit your pegunta, providing that sample, use dput(dados) to capitulate to.

  • Thanks Fernandes, but I just solved it. I was trying several combinations here and it worked. My output was small and somehow this was getting in the way of some x-axis values. All I did was increase the lateral dimensions of the graph and it worked.

  • 1

    It would be interesting then to answer the question with your solution, so that other people, in the future, arrive here and see how to increase the lateral dimensions of the graph.

  • Whoa, that’s my mistake. As I use Rstudio, well above where the chart is, there is an option with the name "Export", then "Save as pdf" and then it lets you put the file dimensions. It was at this point that I was testing combinations. Then just save.

  • As @Marcusnunes suggested, answer your question in the field below, not in the comments. Thus, this question is no longer marked as "unanswered". In addition, why do a boxplot between two numerical variables? Wouldn’t it be better to make a scatter chart?

1 answer

1

Possibly this problem of not being able to visualize the boxplots is due to the type of variables. Since both are numerical (from the description of your text), you should not use such a graph. Such a graph should be used when having a numeric variable and 1 or 2 categorical.

Creating the Boxplot example of Age and Weight:

set.seed(123234)
dados <- data.frame(Peso = rnorm(150, 80, 20),
           Idade = round(rnorm(150, 70, 25)))
boxplot(dados$Peso ~ dados$Idade,
        xlab='Idade', ylab='Weight (grams)',
        outline=F)

inserir a descrição da imagem aqui

As the Idade is a numeric variable, for each of the Ages the function boxplot will create a boxplot for Peso. This is why in most cases there is only one risk (if not, it means that at least 2 people are the same age), which in this case represents the median. Such a representation is completely wrong. Correct is a graph of scattering:

inserir a descrição da imagem aqui

Browser other questions tagged

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