Home > front end >  To represent barplot in viridis color palette
To represent barplot in viridis color palette

Time:05-30

I am trying to use viridis color plate to represent the following excel data: enter image description here to show Forest Percent with respect to GaPa_NaPa in barplot. I try to represent the Forest Percent using code: ggplot(data=Rupandehi_Forest,aes(x=Forest Percent, fill=Forest Percent)) geom_bar(). The result obtained was:- enter image description here. Thus, how can this be represented using viridis color and Forest Area(In Ha) be represented with respect to GaPa_NaPa.

CodePudding user response:

Here is one way how we could do it:

library(tidyverse)

df %>% 
  count(Forest_Percent) %>% 
  ggplot(aes(x=factor(Forest_Percent), y= n, fill=Forest_Percent))  
  geom_col() 
  labs(x="Forest Percent") 
  scale_fill_viridis_d() 
  geom_text(aes(label = n), vjust = 1.5, colour = "white") 
  theme_bw()

enter image description here

data:

df <- structure(list(District = c("RUPANDEHI", "RUPANDEHI", "RUPANDEHI", 
"RUPANDEHI", "RUPANDEHI", "RUPANDEHI", "RUPANDEHI", "RUPANDEHI", 
"RUPANDEHI", "RUPANDEHI", "RUPANDEHI", "RUPANDEHI", "RUPANDEHI", 
"RUPANDEHI", "RUPANDEHI", "RUPANDEHI"), GaPa_NaPa = c("Gaidahawa", 
"Kanchan", "Kotahimal", "Marchawari", "Mayadevi", "Omsatiya", 
"Rohini", "Sammarimal", "Siyari", "Sudhdhodhan", "Devdaha", "Lumbini Sanskritik", 
"Sainamaina", "Siddharthanagar", "Tillotama", "Butwal"), TotalAreaIn_ha = c(9657L, 
5835L, 5812L, 4844L, 7228L, 4844L, 6449L, 5066L, 6620L, 5743L, 
13667L, 11194L, 16082L, 3595L, 12592L, 10139L), ForestAreaIn_ha = c(726L, 
1276L, 0L, 0L, 0L, 1L, 17L, 0L, 142L, 20L, 7352L, 0L, 9115L, 
11L, 1358L, 4958L), Forest_Percent = c("7.50%", "21.90%", "0.00%", 
"0.00%", "0.00%", "0.00%", "0.30%", "0.00%", "2.10%", "0.30%", 
"53.80%", "0.00%", "56.70%", "0.30%", "10.80%", "48.90%")), class = "data.frame", row.names = c("1", 
"2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", 
"14", "15", "16"))
  • Related