I am playing around with a dataset and practicing out some visualizations using ggplot2. My dataset has a column year with 'int' datatype. While plotting, the years get converted to decimal forms. I do not want that.
Following is the code:
cases_over_11_years = Suicides_in_India %>%
select(Year, Total) %>%
arrange(Year) %>%
group_by(Year) %>%
summarize(Total = sum(Total))
options(repr.plot.width = 12, repr.plot.height = 10)# plot dimensions
plot1 = ggplot(data = cases_over_11_years)
plot1 + geom_step(aes(x = Year, y = Total), stat = "identity", size = 1, color = "red") +
labs( title = "Change in numbers over the time for 11 years",
x = "Year",y = "Cases per year")+
theme(axis.text = element_text(size = 18)) +
theme(axis.title = element_text(size = 20)) +
theme(plot.title = element_text(size=22))
This produces the plot:
I want x-axis labels simply in YYYY format. Also, I don't want to change the data type to the character.
Attaching sample dataset
structure(list(State = c("Punjab", "Manipur", "Haryana", "Karnataka",
"Punjab", "Puducherry", "Arunachal Pradesh", "Nagaland", "Chandigarh",
"Tamil Nadu"), Year = c(2001L, 2002L, 2008L, 2002L, 2004L, 2002L,
2001L, 2009L, 2005L, 2009L), Type_code = c("Causes", "Means_adopted",
"Causes", "Means_adopted", "Causes", "Causes", "Means_adopted",
"Means_adopted", "Means_adopted", "Causes"), Type = c("Cancellation/Non-Settlement of Marriage",
"By Drowning", "Dowry Dispute", "By Consuming Insecticides",
"Illness (Aids/STD)", "Cancer", "By Machine", "By Drowning",
"By Hanging", "Insanity/Mental Illness"), Gender = c("Male",
"Male", "Female", "Female", "Male", "Female", "Female", "Male",
"Male", "Female"), Age_group = c("45-59", "60+", "0-14", "45-59",
"0-14", "60+", "0-14", "45-59", "0-14", "15-29"), Total = c(0L,
0L, 0L, 62L, 0L, 0L, 0L, 0L, 0L, 38L)), class = "data.frame", row.names = c(NA,
-10L))
Thankyou for your time :)