4
votes

I'm new to R so I haven't figured out how to apply the same changes to multiple data frames and plot from each resultant data frame. I've done this by plugging in each input csv one by one in an R markdown file.

I created 5 data frames (only showing 3 here) from the same starting format in input file, using the same set of manipulations to get a "plottable" data frames that look like this (only the top few rows presented here). Only the "Stat" varies:

Df1-HAtype:

    Stat    Segment NullbyObs   id  stars
49  H4  HA  0.297083314 1   ***
25  H13 HA  0.09558552  2   ***
57  H5  HA  0.150072798 3   ***
9   H10 HA  0.184111297 4   ***
33  H2  HA  0.182582378 5   ***
81  H9  HA  0.341334025 6   ***
73  H7  HA  0.256536424 7   ***
65  H6  HA  0.260052443 8   ***
41  H3  HA  0.504939556 9   **
1   H1  HA  0.260205358 10  ***
17  H11 HA  0.503464461 11  **
56  H4  PB2 0.184828306 12  ***
32  H13 PB2 0.298094661 13  **
64  H5  PB2 0.199737211 14  ***

Df2-Season:

    Stat    Segment NullbyObs   id  stars
25  spring migration    HA  0.309504658 1   ***
17  overwintering   HA  0.423053354 2   *
9   breeding    HA  0.712614687 3   .
1   autumn migration    HA  0.586144734 4   .
32  spring migration    PB2 0.318294644 5   ***
24  overwintering   PB2 0.450508305 6   ***
16  breeding    PB2 0.636836392 7    

Df3-HostType:

    Stat    Segment NullbyObs   id  stars
17  OD  HA  0.447867405 1   *
25  YAG HA  0.192755193 2   ***
9   MD  HA  0.337331563 3   **
1   BMG HA  0.42653249  4   *
24  OD  PB2 0.271704769 5   ***
32  YAG PB2 0.260490477 6   ***
16  MD  PB2 0.446735462 7   **

I use this code to plot from each data frame:

plot <- ggplot(data = plotdata,
       aes(x = Segment, y = Stat, fill = NullbyObs)) + 
       geom_tile() +
       scale_fill_distiller(palette = "RdYlBu", trans = "log10") +
       labs(y=NULL, x=NULL, fill="Null/Obs") +
       geom_text(aes(label=stars), color="black", size=4) +
       coord_equal()

plot

Why is the legend for the plot shown for Df1-HAtype but is missing from the plot for Df2-Season and Df3-HostType???

1
To me this looks a bug, so I posted an issue: No legend with trans = log10 for certain fill/color valuesHenrik

1 Answers

3
votes

Add breaks=seq(0,1,0.1) inside scale_fill_distiller

plotdata <- Df2_Season
p <- ggplot(data = plotdata , aes(x = Segment, y = Stat, fill = NullbyObs)) + 
     geom_tile() +
     scale_fill_distiller(palette = "RdYlBu", trans = "log10", 
                          breaks=seq(0,1,0.1), labels=seq(0,1,0.1)) +
     labs(y=NULL, x=NULL, fill="Null/Obs") +
     geom_text(aes(label=stars), color="black", size=4) +
     coord_equal()
p

Df2_Season enter image description here

Df3_HostType enter image description here