Create an exploratory chart type weight~collection by filtering treatments in R

Asked

Viewed 159 times

1

With the tapply function I can know their values:

tapply(peso, list(coleta, tratamento), mean, na.rm=T)
tapply(peso, list(coleta, tratamento), sd, na.rm=T)
sd
    Biofloc  Control
A1       NA       NA
A2 20.69427 26.05011
A3 18.70375 29.34639
A4 19.22748 30.06533
A5       NA 31.81934
A6 24.03980 34.30186
A7 29.94012 39.98731
A8 29.29967 45.16424

I wonder how to plot this in R, because the functions used do not return me what I want.

  • 1

    Try to edit your question because it is not clear. The original question states "the functions used do not return me what I want", but we do not know what you want. The question title speaks in "exploratory chart type weight ~ collecting filtering treatments", but what does it mean? Is it a scatter chart? Boxplot? It is a graph with averages and standard deviations?

  • Right. I have a data set that has the following variables, weight, collection and treatment. I want a graph that shows me the average weight per collection and treatment, can be barplot, boxplot as long as I can discriminate the average weight per collection and treatment. When I say the functions I tried to use, I talk about "subset", trying to filter inside a boxplot. Ex: boxplot(weight~collection, subset = treatment ="Biofloc") then it returns me 1 graph only with these variables and for this specific treatment and I want the all in one graph.

1 answer

2

I think of two types of graphics for your situation, but all around different packages than you used, (base R).

But keep going like I would, it might help you!

First Gero some data that seem to have the same structure as yours:

library(tidyverse)
n <-100
set.seed(42)
theme_set(theme_minimal())
tb <- 
    tibble(
    coleta = map_chr(1:5 , ~paste('A', . , sep = '')) %>% 
             rep(20),
    tratamento = rbinom(size = 1, n = 100, prob = 0.5),
    peso = rnorm(mean = tratamento*0.03, 100),
    tratamento_char = tratamento %>% paste('tratamento', .)
)

The first way is by using a facet for each treatment, which I do not like very much in the case of treatment itself, because you do not see the effect of a change directly:

tb %>% 
    group_by(coleta, tratamento_char) %>% 
    summarise(avg = mean(peso)) %>% 
    ggplot(data = . , aes(x = coleta, y = avg)) +
    geom_point() +
    facet_wrap(~ tratamento_char)

método 1

The second method is more minimalist, but passes the message well, as it facilitates the comparison of treatments in a collection:

tb %>% 
    group_by(coleta, tratamento_char) %>% 
    summarise(avg = mean(peso)) %>% 
    ggplot(data = . , aes(x = coleta, y = avg)) +
    geom_point(aes(color = tratamento_char, 
                   pch = tratamento_char), size = 2)

método 2

The last method, is my favorite, because it facilitates the comparison between the groups and shows the trend of the whole in the experiment.

tb %>% 
    group_by(coleta, tratamento_char) %>% 
    summarise(avg = mean(peso))  %>% 
    ggplot(data = . , aes(x = tratamento_char, y = avg)) +
    geom_point(aes(color = coleta)) +
    geom_line(aes(group = coleta, color = coleta), 
              alpha = 0.2, 
              size = 2.5)

método 3

  • Good afternoon. Thank you very much for the help, I had not yet taken to study ggplot2, I’ve heard and seen very good graphics made with this package. Now there’s not much escape.

Browser other questions tagged

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