Ggplots with one variable

Hi! I'm very new to R, so sorry if this is an obvious question. I'm trying to visualise a relationship between weight (numeric) and sex (factor), however I only want to look at males and not all entries within the sex factor.

How do I have R only consider one value within a column? Should I use the drop function? If anyone could point me in the right direction that would be awesome.

Thank you, sorry if anything isn't clear.

One solution might be to subset males into new dataframe. Another solution is to create a column with dummy variables that equals one for males.

For example:

df$Male <- ifelse(df$Sex == "male", 1,  0)

And now try your ggplot.

Here is an example with made-up sample data (BTW you should make your questions providing a REPRoducible EXample (reprex) as the one bellow).

set.seed(123) # For reproducibility

sample_data <- data.frame(
    weight = runif(10, 50, 80),
    sex = sample(c("Male", "Female"), size = 20, replace = TRUE)

sample_data %>% 
    filter(sex == "Male") %>% 
    ggplot(aes(y = weight, x = sex)) +

Created on 2020-02-02 by the reprex package (v0.3.0)

I completely forgot about subsets, shows what a novice I am!

NoFemale <- FishData %>% filter(Sex == "male")

seemed to work for my purposes but I'm unsure if this is the best way. I'll try your other suggestions method as well.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.