How to have two varible on the Y axis?

Hi all

I want to make it so that I have two columns on the X-axis, one for "exposed_average" and one for "shaded_average" without having to change the formatting of the imported data. How can I do this? I know how to make a graph with one variable per axis but I don't know how I'd have multiple.

I just want the Y-axis to show the number of seedlings ( the things I was counting). Do I need something predefined to make a Y-axis?

Thanks

my_data <- read.csv("Shade_exposed_proper.csv")
summary(my_data)
#>       Plot          Shaded         Exposed     
#>  Min.   :1.00   Min.   :10.00   Min.   :130.0  
#>  1st Qu.:2.25   1st Qu.:17.50   1st Qu.:178.0  
#>  Median :3.50   Median :34.50   Median :296.0  
#>  Mean   :3.50   Mean   :35.50   Mean   :277.3  
#>  3rd Qu.:4.75   3rd Qu.:52.25   3rd Qu.:365.2  
#>  Max.   :6.00   Max.   :64.00   Max.   :415.0
head(my_data)
#>   Plot Shaded Exposed
#> 1    1     64     321
#> 2    2     16     147
#> 3    3     47     380
#> 4    4     10     415
#> 5    5     22     130
#> 6    6     54     271
shaded <- my_data [, 2]
exposed <-  my_data [,3]
shaded_average <- mean(my_data[,2])
exposed_average <-mean(my_data [,3])


graph <- ggplot(my_data, aes(shaded_average,exposed_average ))+ 
                  geom_col (width = 0.5)

graph <-  graph + labs(x = "Exposure", y = "Seedling Count avg.")
print (graph)

You are still not providing sample data in a proper format, I have used the six rows you are showing as sample data. Is this what you mean?

library(tidyverse)

# Sample data on a copy/paste friendly format
# Replace this part with my_data <- read.csv("Shade_exposed_proper.csv")
my_data <- data.frame(
        Plot = c(1, 2, 3, 4, 5, 6),
      Shaded = c(64, 16, 47, 10, 22, 54),
     Exposed = c(321, 147, 380, 415, 130, 271)
)

my_data %>% 
    gather(variable, mean, Shaded:Exposed) %>% 
    group_by(variable) %>% 
    summarise(mean = mean(mean)) %>% 
    ggplot(aes(x = variable, y = mean, fill = variable)) +
    geom_col(width = 0.5)

Thanks. I thought I’d provided it right this time. Sorry. What’s should I have done instead?

We don't have access to your local files so we can't copy your code into our own R session and try to solve your problem, that is why you have to provide sample data on a copy/paste friendly format (as I did on my previous answer) to learn how to do it, read the reprex guide on this link, it is easier than I seems, give it a try.

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