HertieDataScience / SyllabusAndLectures

Hertie School of Governance Introduction to Collaborative Social Science Data Analysis
MIT License
37 stars 60 forks source link

Changing x axis of histogram #65

Closed mr-r0b0t closed 8 years ago

mr-r0b0t commented 8 years ago

Hi everyone,

I was wrapping my head around this problem, but couldn't fix it unfortunately... Maybe someone can help.

Basically, I would like to change the label of the x axis so that it only shows full numbers (e.g. "1", "2", etc.) and not "0.5" "1" "1.5" etc that are centered beneath each single bar.

I tried many different things, but they all didn't print what I would like to get. Here's the relevant code to reproduce the issue (histogram (2) as comparison and how I would like (1) to look):

Load relevant dataset

Model_1_Dataset <- read.csv("https://raw.githubusercontent.com/KatrinHeger/CollaborativeResearchProject/master/Model_1_Dataset.csv")

Create histogram (1) (the one to fix)

hist(Model_1_Dataset$gtypesup_cat, main = "Frequency of Government Support Types", xlab = "Government Support Types", las = 1, breaks = seq(.5,3.5,1), col = "lightblue")

Create desired histogram (2) as comparison

hist(Model_1_Dataset$outcome_d, main = "Frequency of Conflict Outcomes", xlab = "Conflict Outcomes", las = 1, breaks = seq(-.5,3.5,1), col = "lightgreen")

Thank's a lot!

Best,

Benedikt

mr-r0b0t commented 8 years ago

We could resolve it by using the qplot function of the ggplot2 package.

christophergandrud commented 8 years ago

This is easy to do with ggplot2. The key thing is scale_x_continuous(breaks = c(1, 2))

mr-r0b0t commented 8 years ago

Thank's a lot!