Skip to content

Instantly share code, notes, and snippets.

@juanchiem
Last active August 15, 2022 09:53
Show Gist options
  • Save juanchiem/d0d23acebee3793d1472089436971d74 to your computer and use it in GitHub Desktop.
Save juanchiem/d0d23acebee3793d1472089436971d74 to your computer and use it in GitHub Desktop.
da <- read.csv("https://raw.githubusercontent.com/juanchiem/agro_data/master/spores.csv",
sep = ";")
da %>%
group_by(meter, spore_nuclei, .drop=FALSE) %>%
summarise(count = mean(count)) %>%
mutate(percent = count/sum(count)) %>%
# group_by(meter, spore_nuclei) %>%
# mutate(tot = sum(count))
ggplot(aes(x=meter, y=percent, fill=factor(spore_nuclei) ))+
geom_bar(position="fill", stat="identity")+
labs(y="Type of spore frequency")+
scale_fill_viridis_d(direction = -1)+
geom_text(aes(label = round(percent,2)), position = position_stack(vjust = .5),
col = "white", fontface = "bold", size = 3)+
theme_bw()
# si fuera una escala de severidad agregamos la escala traffic:
mycols <- colorRampPalette(c("red2", "orange", "gold1", "forestgreen"))
myvals <- c(0, .25, .5, .75, 1)
da %>%
group_by(meter, spore_nuclei, .drop=FALSE) %>%
summarise(count = mean(count)) %>%
mutate(percent = count/sum(count)) %>%
ggplot(aes(x=meter, y=percent, fill=fct_rev(factor(spore_nuclei))))+
geom_bar(position="fill", stat="identity")+
labs(y="Type of spore frequency")+
# scale_fill_viridis_d(direction = -1)+
scale_fill_manual(values=mycols(5), name="Escala sev") +
geom_text(aes(label = round(percent,2)), position = position_stack(vjust = .5),
col = "white", fontface = "bold", size = 3)
@juanchiem
Copy link
Author

image

@juanchiem
Copy link
Author

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment