Reputation: 313
my dataframe currently looks like this
N = 61
MChange <- rnorm(N)
FChange <- rnorm(N)
Industry <- sample(N)
industry020406 <- data.frame(Industry, MChange, FChange)
Using the following code:
ggplot(industry020406, aes(reorder(Industry, MChange), MChange)) +
geom_col() +
labs(x = "Industry",
y = "Tariff Cut (Percentage Points)") +
theme(axis.text.x = element_text(angle = 90))+
coord_flip()
my barchart looks like this:
Since it is difficult to identify changes that are significant, is there a way I can filter out MChange that is between -1
and 1
within the ggplot
function?
Thank you.
Upvotes: 1
Views: 1042
Reputation: 35584
You can do the filtering in xlim()
:
x.lab <- with(industry020406, reorder(Industry, MChange)[MChange >= -1 & MChange <= 1])
ggplot(industry020406, aes(reorder(Industry, MChange), MChange)) +
geom_col() +
coord_flip() +
xlim(sort(x.lab))
Upvotes: 0
Reputation: 173978
Yes, just filter it as normal, e.g. with dplyr::filter
ggplot(dplyr::filter(industry020406, MChange < 1 & MChange > - 1),
aes(reorder(Industry, MChange), MChange)) +
geom_col() +
labs(x = "Industry",
y= "Tariff Cut (Percentage Points)") +
theme(axis.text.x = element_text(angle = 90))+
coord_flip()
Upvotes: 1