Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I only plot values over a certain number in ggplot?

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

enter image description here

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.

>Solution :

You can do the filtering in xlim():

ggplot(industry020406, aes(reorder(Industry, MChange), MChange)) +
  geom_col() +
  coord_flip() +
  xlim(sort(reorder(Industry, MChange)[MChange >= -1 & MChange <= 1]))

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading