2

I am trying to plot water quality by 3 districts of a nation. I have plot the map according to Biological Oxygen Demand value from the table as shown below:- enter image description here

The code I used is as shown:-

install.packages("cartography")
install.packages("sf")
install.packages("tidyverse")
library(cartography)
library(sf)
library(tidyverse)
setwd("C:/Users/lenovo/Desktop/IEM")
KathmanduWaterQlty<-st_read("KathmanduValley.shp")
View(KathmanduWaterQlty)
ggplot(data=KathmanduWaterQlty)+geom_sf(aes(fill=BOD), color="black")+
scale_colour_brewer(palette="1") +
xlab("Longitute")+ ylab("Latitude")+
ggtitle("Biological Oxygen Demand of Water in Kathmandu Valley")

Though I got the map displayed but the color is not appealing to look at. How can this be changed to different color type that looks more pleasing to look at. Also, how can title be centered and x-axis and y-axis be removed? The final displayed is:- enter image description here

1 Answer 1

3

Since you are using ggplot2, you should have a look to:

  1. scale_fill_* options. There is plenty of options on ggplot2, and you can create your own with scale_fill_gradientn(). See https://ggplot2.tidyverse.org/reference/index.html#scales
  2. For modifyying theme elements, have a look to the theme possibilites: https://ggplot2.tidyverse.org/reference/theme.html.

A good place to get answers on ggplot2 is https://stackoverflow.com/questions/tagged/ggplot2


library(dplyr)
# An example data, use yours
KathmanduWaterQlty <- giscoR::gisco_get_nuts(country = "Italy", nuts_level = 2) %>%
  mutate(BOD = sample(1:5, 21, replace = TRUE))

library(ggplot2)

ggplot(data = KathmanduWaterQlty) +
  geom_sf(aes(fill = BOD), color = "black") +
  xlab("Longitute") +
  ylab("Latitude") +
  ggtitle("Biological Oxygen Demand of Water in Kathmandu Valley") +
  # Change palette
  scale_fill_gradientn(colours = c("yellow","red", "blue")) +
  theme(
    axis.text = element_blank(),
    axis.ticks = element_blank(),
    plot.title = element_text(size=13, hjust = .5, face = "bold")
  )

enter image description here

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.