I created a histogram in R. At the moment, the numbers 1 - 8 are written on the x-axis (for each number a bar). I would like to change the numbers into the wind direction, e.g. instead of 1, there should stand "west". I tried:
scale_x_discrete(labels=c("1" = "North", "2" = "North East", "3" = "East", "4"= "South East", "5"= "South", "6"="South West", "7"="West", "8"="North West"))
But is not working.I also tried:
scale_x_discrete(breaks=c("1","2","3", "4", "5", "6", "7", "8"), labels=c("North", "North East", "East", "South East", "South", "South West", "West", "North West"))
Here is my script:
options(stringsAsFactors = FALSE)
input1 <- "C:\\Users\\wind_direction.csv"
wind_direction <- read.csv(input1, sep=";")
library(ggplot2)
p3 <- ggplot(wind_direction, aes(x=winddirection)) +
geom_bar(color="black", fill="grey", width=0.9)+
theme_bw() +
scale_y_continuous(limits = c(0, 55), breaks = seq(0,55,10),expand=c(0,0)) +
scale_x_discrete(labels = c("1" = "North", "2" = "North East", "3" = "East", "4"= "South East", "5"= "South", "6"="South West", "7"="West", "8"="North West"))
print(p3)
Here is a sample of my data:
head(wind_direction)
day time winddirection
1 31.07.2018 12:51:57 3
2 31.07.2018 12:55:16 3
3 31.07.2018 12:56:29 3
4 31.07.2018 13:25:05 3
5 31.07.2018 13:36:54 3
6 31.07.2018 13:55:37 3