R: gradient fill for geom_rect in ggplot2

后端 未结 1 1494
有刺的猬
有刺的猬 2020-12-18 11:12

I want to create in R a graphic similar to the one below to show where a certain person or company ranks relative to its peers. The score will always be between 1 and 100.

相关标签:
1条回答
  • 2020-12-18 12:03

    I think that geom_tile() will be better - use sales for y and fill. With geom_tile() you will get separate tile for each sales value and will be able to see the gradient.

    ggplot(mydf) +
      geom_tile(aes(x = 1, y=sales, fill = sales)) +
      scale_x_continuous(limits=c(0,2),breaks=1)+
      scale_fill_gradient2(low = 'blue', mid = 'white', high = 'red', midpoint = 50) +
      theme_minimal()
    

    enter image description here

    0 讨论(0)
提交回复
热议问题