Reputation: 3600
This is the desired output: similar to output by subsetting
I am using scale_x_discrete to set the limits of the x axis. I would like to know how to get rid of the blank space left on the panel and have the defined limits fill the entire axis.
myplot <- ggplot(diamonds, aes(x = clarity, fill = cut)) + #data
geom_bar() + #geom
scale_x_discrete(limits = c("I1", "SI2", "VS2"),
name = "Clarity of Stones") #setting limits #limits
myplot
Upvotes: 1
Views: 368
Reputation: 8377
Its probably just a syntax problem since you missed a parenthesis at the end of your limits
argument, and the name of the scale is wrongly passed as a fourth column of your X-axis. You shoud run:
ggplot(diamonds, aes(x = clarity, fill = cut)) + geom_bar() +
scale_x_discrete(limits = c("I1", "SI2", "VS2"), name = "Clarity of Stones")
Upvotes: 0
Reputation: 1664
If your goal is to subset your data for particular measures (clarity in this case), you should do this within the data object provided. As in:
ggplot(diamonds[diamonds$clarity %in% c("I1", "SI2", "VS2"),], aes(x = clarity, fill = cut)) +
geom_bar()
Upvotes: 1