Aula5

Author

ARLAM

Segundo plot

Importa 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)
mg <- read_excel("C:dados-diversos.xlsx")

Visualiza

p_box <- mg |> 
  ggplot(aes(trat, comp))+
  #geom_point()+
  geom_boxplot(outlier.color = NA,
               fill = "orange",
               size = 0.5,
               width = 0.4)+
  geom_jitter(width = 0.1, 
              height = 0,
              size =2,
              color = "black")+
  scale_y_continuous(limits = c(7,19),
                     n.breaks = 6)+
  labs(y = "Lesion size (mm)",
       x = " ")+
  theme_bw()
p_box

ggsave("figs/plot2.png",
         width = 4,
       height = 4,
       bg = "white")
library(ggthemes)
Warning: package 'ggthemes' was built under R version 4.2.3
p_means <- mg |> 
  group_by(trat) |> 
  summarise(comp_mean = mean(comp),
            comp_sd = sd(comp)) |> 
  ggplot(aes(trat, comp_mean))+
  #geom_col(fill = "orange",
   #        width = 0.5)+
  geom_point()+
  scale_y_continuous(limits = c(7,18),
                     n.breaks = 6)+
  geom_errorbar(aes(ymin = comp_mean - comp_sd , 
                    ymax = comp_mean + comp_sd,
                    width = 0.05))+
  theme_bw()+
  labs(y = "Lesion size (mm)",
       x = " ")
p_means

ggsave("figs/mean_sd.png",
       width = 4,
       height = 4,
       bg = "white")

composição de plots

library(patchwork)
Warning: package 'patchwork' was built under R version 4.2.3
(p_box | p_means) +
  plot_annotation(tag_levels = 'A',
                  title = 'Gráficos que impressionam')

ggsave("figs/combined.png")
Saving 7 x 5 in image
survey <- read_excel("C:dados-diversos.xlsx",
                     sheet = "survey")

survey |> 
  filter(state == "RS") |> 
  count(species, residue) |> 
  ggplot(aes(species, n))+
  geom_col(width = 0.4, 
           fill = "steelblue")+
   coord_flip()+
  facet_wrap(~residue, ncol = 1)+
  labs(x = "", y = "Number of isolates",
       title = "Horizontal bar plot",
       subtitle = "Using ggplot")+
  theme_bw()

ggsave("figs/barplot.png", bg = "white")
Saving 7 x 5 in image