0

Hey all I have a dataset called features of 2100 images of letters, numbers and mathematical functions, there are many columns in this dataset including 'height' and 'width' I am trying to create a histogram that represents the heights of these images when they are a mathematical function. And another histogram when they are numbers or letters.

The variable is.mathtrue is a Logical variable, it prints TRUE when the images are a mathematical symbol, and prints FALSE when they are numbers or letters.

p3 <-ggplot(features, aes(height)) + 
geom_bar() + 
ggtitle("A histogram of when height is mathematical")

p3 

I am able to create a histogram of all of the 'height' but I am unsure how to use my is.mathtrue variable to get the histogram to only represent the mathematic symbols.

Any help on this would be great as I'm rather lost.

Thanks.

r2evans
  • 141,215
  • 6
  • 77
  • 149
  • 2
    Sample data, please. (Read https://stackoverflow.com/q/5963269, [mcve], and https://stackoverflow.com/tags/r/info.) – r2evans Apr 22 '22 at 16:12
  • Can you share your data? Please run `dput(head(yourdatasetname))` and copy and paste the output in your question. Why are you using `geom_bar` and not `geom_histogram` if you want a histogram? – Andrea M Apr 22 '22 at 16:12
  • Are you simply looking for `ggplot(filter(features, is.mathtrue), aes(height)) + ... ` ? – langtang Apr 22 '22 at 16:14

1 Answers1

0

If I understand your question correctly.

ggplot(features, aes(height)) + 
geom_bar() + 
ggtitle("A histogram of when height is mathematical") +
facet_wrap(vars(is.mathtrue))

I can’t test this without your dataset. Also this will produce a bar chart, not a histogram. To make a histogram you need geom_histogram.

Andrea M
  • 2,314
  • 1
  • 9
  • 27