Closed klg-2016 closed 4 years ago
Here are some resources for adding color to ggplot:
https://www.r-graph-gallery.com/ggplot2-color.html http://www.sthda.com/english/wiki/ggplot2-colors-how-to-change-colors-automatically-and-manually https://michaeltoth.me/a-detailed-guide-to-ggplot-colors.html http://www.cookbook-r.com/Graphs/Colors_(ggplot2)/
On Fri, Sep 4, 2020 at 10:42 AM klg-2016 notifications@github.com wrote:
So I understand that this is the code that creates the species occupancy/environmental covariates plots, but I'm struggling to think about where/how I would input different colors for the 4 species. Do you have any suggestions?
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/kaitlyngaynor/gorongosa-mesocarnivores/issues/85, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHA7WT6RDSPLPG4JFSKTFLTSEERHPANCNFSM4QY77FIQ .
-- Kaitlyn Gaynor Postdoctoral researcher National Center for Ecological Analysis and Synthesis University of California - Santa Barbara
I would probably make an extra data column that was a key for color (via join), and map the aesthetics to this. the 4 focal species would have their own keys, and the other species would have the same key that was just mapped to black
ex. make new dataframe with columns for "color_group" and "Species" in R, and then left-join this to the data frames you are plotting, and set the col aesthetic to this "color_group" variable
color_key <- data.frame(color_group = c("col1", "col2", "col3", "col4", "col5", "col5", "col5", "col5", "col5", "col5"), Species = unique(originaldataframe$Species))
where you repeat "col5" for the proper length depending on how many species you have
Thank you! I believe that all makes sense conceptually, I'll see how it goes implementing it.
Ok. My lazy way is often to just do it after the fact in figure editing software....
On Fri, Sep 4, 2020 at 11:03 AM klg-2016 notifications@github.com wrote:
Thank you! I believe that all makes sense conceptually, I'll see how it goes implementing it.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/kaitlyngaynor/gorongosa-mesocarnivores/issues/85#issuecomment-687299857, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHA7WT7T4FTRTCUT6YTAB3LSEETXLANCNFSM4QY77FIQ .
-- Kaitlyn Gaynor Postdoctoral researcher National Center for Ecological Analysis and Synthesis University of California - Santa Barbara
Here's an example with a key I did it so I could specify group and factor order—same logic applies:
On Fri, Sep 4, 2020 at 11:06 AM Kaitlyn Gaynor gaynor@nceas.ucsb.edu wrote:
Ok. My lazy way is often to just do it after the fact in figure editing software....
On Fri, Sep 4, 2020 at 11:03 AM klg-2016 notifications@github.com wrote:
Thank you! I believe that all makes sense conceptually, I'll see how it goes implementing it.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/kaitlyngaynor/gorongosa-mesocarnivores/issues/85#issuecomment-687299857, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHA7WT7T4FTRTCUT6YTAB3LSEETXLANCNFSM4QY77FIQ .
-- Kaitlyn Gaynor Postdoctoral researcher National Center for Ecological Analysis and Synthesis University of California - Santa Barbara
-- Kaitlyn Gaynor Postdoctoral researcher National Center for Ecological Analysis and Synthesis University of California - Santa Barbara
I would totally go that route if I had figure editing software/.knew how to use it >.<
Thank you! I'm tackling the figures from the Rota model first because they're easier, and will come back to this after.
subset(Factor == "tree_hansen") %>%
is that also subsetting so you're only including mesocarnivore speces?
it's line 60
Looks like that line just subsets to the tree covariate...
This model only included the mesocarnivores so there shouldn't be any need to subset to them at this stage (I did it before running the model)
even though Spp reads in all species/traits?
ex. make new dataframe with columns for "color_group" and "Species" in R, and then left-join this to the data frames you are plotting, and set the col aesthetic to this "color_group" variable
color_key <- data.frame(color_group = c("col1", "col2", "col3", "col4", "col5", "col5", "col5", "col5", "col5", "col5"), Species = unique(originaldataframe$Species))
where you repeat "col5" for the proper length depending on how many species you have
with this suggestion, I'm confused on how I know (or set) which order the species would be listed in? so I understand what you're recommending but not how to use this to implement it.
Yes, because you use left_join in line 21 to join sppcov to Spp.
from the internet: "A left join in R is a merge operation between two data frames where the merge returns all of the rows from one table (the left side) and any matching rows from the second table. A left join in R will NOT return values of the second table which do not already exist in the first table."
So in this case, any species from the second table that are not in the first table do not get joined in
On Fri, Sep 4, 2020 at 2:45 PM klg-2016 notifications@github.com wrote:
even though Spp reads in all species/traits?
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/kaitlyngaynor/gorongosa-mesocarnivores/issues/85#issuecomment-687405228, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHA7WT4ISL7HLLVUUEDXZR3SEFNY3ANCNFSM4QY77FIQ .
-- Kaitlyn Gaynor Postdoctoral researcher National Center for Ecological Analysis and Synthesis University of California - Santa Barbara
Got it, that makes sense--thank you!
Ah we have multiple issues in the issue oops. Regarding your question about the key, the order of the species doesn't matter at all. It will get left_joined! So, see above answer for what this means, haha.
Oh but if you want to know what order the species are in if use that code, you can just type this into the console unique(originaldataframe$Species)
(but change the name of the dataframe) and it will list the order of the species. Then just set the order of the color keys to match. The color keys are really just placeholders, the values don't matter at all, the point is just to distinguish your 4 species and then lump the rest into the same category
Sorry if my explanations are unclear today, my brain is a bit fried
Sorry I didn't even realize that my trouble with this was not understanding how a left join works! Thank you--I'll work with that.
You're good--my brain is also a little fried today from trying to take care of all the "little" things that are left to finalize. So thank you!
I got it!
(it's a little tricky to tell the green and the black apart, but I might just leave it, esp given this was something to make it nicer throughout but not necessarily something that is necessary to understanding the graph)
Cool! I would recommend two changes, which are pretty straightforward and would make it easier to read. I went ahead and too the liberties of doing these myself in your code, so you'll see it if you pull:
1) make the points bigger (change size = 2 to size = 3 or something)
2) make the CIs colored as well (this should be as easy as adding the color the aes of the ggplot argument rather than the geom_point... but it looks like you took a different creative approach to coloring the points, haha, so I redid it...)
Those both sound great to me. I could not get it to work thinking like that, but this looks great!
(when I was trying to write the code to pull it together; it runs fine now!)
https://github.com/kaitlyngaynor/gorongosa-mesocarnivores/blob/72f752ac5094bb47536ade200bcdd7b1bbee81d8/scripts/alternative-multispecies-model/04-species-covariate-plot.R#L51
So I understand that this is the code that creates the species occupancy/environmental covariates plots, but I'm struggling to think about where/how I would input different colors for the 4 species. Do you have any suggestions?