0

my program iterates through column variables in a dataframe and plots them. It uses the ggtree library to plot them. The code (simplified) that I believe is the culprit is:

for (col in cols) {

     p <- p + geom_fruit(geom=geom_tile, mapping=aes(fill=get(col)), width=0.002, offset=0.05) + # ISSUE WITH fill = STRAIN
    scale_fill_manual(values=col_vector, name=col) 

}

I don't think its an issue with ggtree, but I believe its got to do with get(col). I believe that get column is getting overwritten, as the plot that results is this:

enter image description here

As you can see from the plot, the 2 columns that I am plotting are exactly the same. Plotting a single column once produces no issues, but I always notice that the second column plot overwrites the first column plot. Could someone offer assistance as to why that is?

MrFlick
  • 195,160
  • 17
  • 277
  • 295
Yasir
  • 33
  • 6
  • 1
    Don't use `get()`. Use `aes(fill=.data[[col]])` or `aes(fill=!!as.name(col))` – MrFlick Apr 13 '21 at 23:54
  • Just another question here, I decided to do the same thing as above but for a continuous scale, the suggestions above don't work for those, and using dd[[col]], while working for only a single scale, experiences the same problems as detailed in this post. Could I get assistance again? (I converted the column from char to numeric). – Yasir Apr 14 '21 at 05:06
  • You can only have one scale per aesthetic for a plot so adding them in a loop doesn’t quite make sense. You should open a new question with a proper reproducible example that shows what you are trying to do. – MrFlick Apr 14 '21 at 05:08

0 Answers0