0

I am working on a plot where my dataset is a simple column of numbers,

count1 -> c(10,10,10,10,9,8,6,4,4,3,3,3) 

for the y-axis, and just a list of room numbers for the y-axis. The data is arranged so that count1's highest values are placed on the left since the room numbers are irrelevant. I am trying to use a color palette which will color the bars based upon their number, i.e. 10 is more important than 8, more important than 4, etc.

I have set the column as.numeric(count1), and tried a few things. RColorbrewer is loaded in, and I just get some random, bad looking colors that indicate RColorbrewer isn't active at all.

Here is my plot code, maybe someone can find my mistake? I imagine the datatype of the room numbers (x-axis) shouldn't matter.

ggplot(fumeNumber3, aes(x = reorder(Location, -count1), y = count1)) + 
        theme(axis.text.x = element_text(angle = 85, hjust = 1)) +
        geom_bar(stat = "identity", fill = (fumeNumber3$count1)) +
        labs(x = "Lab Location", y = "Number of Fume Hoods in lab") +
         scale_fill_brewer(palette = "Blues")
Iridium
  • 23,323
  • 6
  • 52
  • 74
Emery
  • 31
  • 1
  • 8
  • The `fill` aesthetic must be inside `aes()` to get a legend and use the `scale_*` functions. Try `aes(fill = count`)` in your `geom_bar()` layer instead of what you have currently. – aosmith Jun 21 '18 at 15:25
  • @aosmith I actually don't need a legend but dear god it worked. When I add scale_fill_brewer() I get errors.. Any idea why? – Emery Jun 21 '18 at 15:28
  • 2
    I *think* `scale_fill_brewer()` is for discrete values, not continuous. So if `count1` is numeric you could make it a factor or use a continuous scale a la `scale_fill_distiller()`. If you add an example of your dataset folks may be able to give a direct answer. See ideas for how to make a reproducible example [here](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – aosmith Jun 21 '18 at 15:36

0 Answers0