ggplot boxplot help

Hi yall,
I am having trouble creating a box plot because my x variables, in this case, my TFS each have multiple values or in this case the replicates. I want to plot my TF's as my x values and I want to plot each replicate as my y-axis

. If you are able to help pls let me know.

Best Regards,
Gabriel Viramontes

You need to reshape your data so the TF label is in one column and the values are in another. It seems as if the SN250 column is not needed, so I dropped it in the example below. I invented a small data set for this example

library(tidyr)
library(ggplot2)
library(dplyr)

DF <- data.frame(SN250 = 1:3, TF1 = rnorm(3), TF2 = rnorm(3), TF3 = rnorm(3))
DF
#>   SN250       TF1        TF2         TF3
#> 1     1 0.1809112 -0.8879696  0.45406388
#> 2     2 0.4423818  0.9321035  0.31701018
#> 3     3 1.1232862  0.7158731 -0.07038791
DFplot <- DF %>% select(-SN250) %>% #drop the first column
  pivot_longer(cols = TF1:TF3, names_to = "TF", values_to = "Value")
DFplot
#> # A tibble: 9 x 2
#>   TF      Value
#>   <chr>   <dbl>
#> 1 TF1    0.181 
#> 2 TF2   -0.888 
#> 3 TF3    0.454 
#> 4 TF1    0.442 
#> 5 TF2    0.932 
#> 6 TF3    0.317 
#> 7 TF1    1.12  
#> 8 TF2    0.716 
#> 9 TF3   -0.0704
ggplot(DFplot, aes(TF, Value)) + geom_boxplot()

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

Hi, thank you so much for your response.
I have one quick question which is what happened to our 3 replicate values in our new dfplot table since they became one value.

Best Regards,
Gabriel Viramontes

Wait never mind I figured it out thank you once again. If I did want to Transfer my values from my excel sheet to a new table like this how would I go about it?

If I need to import an Excel file I use the read.xlsx() function from the openxlsx package. The code would look like this to read the first sheet.

library(openxlsx)
DF <- read.xlsx("MyFile.xlsx", sheet = 1)

Of course, you have to install the openxlsx package first. If the file is not in R's working directory, you will have to use the full file path instead of just the file name.

An alternative that I have never used can be found in the Import Dataset menu of RStudio. This can be found on the Environment tab which is usually in the top right pane of RStudio. Just below the Environment tab itself, there is a row of icons and one of those is Import Dataset. It seems to use the readxl package.

Hello,

This was exactly the answer I was looking for on my own question I made. If I may also add a small question, instead of boxplot, would it be possible to do a bar graph representing the same type of data shown above and then separate by two groups? Thank you so much!

I would be happy to help you but your question is separate from the question in this thread. Could you please start another thread and include a little bit of your data? Posting the output of

dput(head(DF))

is a good method if you already have your data in a data frame (named DF in my example).

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