aula7

#Transformando os dados

library(tidyverse)
Warning: package 'ggplot2' was built under R version 4.2.3
Warning: package 'tibble' was built under R version 4.2.3
Warning: package 'dplyr' was built under R version 4.2.3
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.2     ✔ readr     2.1.4
✔ forcats   1.0.0     ✔ stringr   1.5.0
✔ ggplot2   3.4.2     ✔ tibble    3.2.1
✔ lubridate 1.9.2     ✔ tidyr     1.3.0
✔ purrr     1.0.1     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(readxl)

mofo <- read_excel("dados-diversos.xlsx", "mofo")
mofo |> 
  ggplot(aes(treat, yld))+
  geom_col()+
  facet_wrap(~study)

Histogram

h <- mofo |> 
  ggplot(aes(scl))+
  geom_histogram(bins = 10)
b <- mofo |> 
  ggplot(aes(scl))+
  geom_boxplot()
library(patchwork)
Warning: package 'patchwork' was built under R version 4.2.3
h / b

mofo2 <- mofo 
h2 <- mofo2 |> 
  ggplot(aes(yld))+
  geom_histogram(bins = 10)
h2

h / h2

survey <- read_excel("dados-diversos.xlsx", "survey")

survey |> 
  filter(state == "RS") |> 
  count(species, residue) |> 
  arrange(n) |> 
  rename(res = residue) |> 
  mutate(n_class = case_when(
          n < 30 ~ "baixa",
          TRUE ~ "Alta"))
# A tibble: 4 × 4
  species res         n n_class
  <chr>   <chr>   <int> <chr>  
1 Fspp    corn       22 baixa  
2 Fspp    soybean    26 baixa  
3 Fgra    corn      147 Alta   
4 Fgra    soybean   255 Alta