0

I am new to R but have some experience with matlab. I am trying to make comparison plots between three different area measurements on one graph faceted by genotype of animal model. I would like to plot Glom.Area, Glom.Tuft, and Mesangial.Area faceted by genotype (control v Cre -).

My code so far:

# Setup
library(tidyverse)
library(ggbeeswarm)
library(readxl)

# work space
setwd("C:/Users/k_nic/OneDrive/Desktop")

# Read in csv file
t1 <- read.csv("sample.csv", header = TRUE)

# plot for one varible
ggplot(t1, aes(x = Genotype, y= Glom.Area))

Dataset:

   Genotype Sex Glom.Area Glom.Tuft Mesangial.Area
1   Control   M  6617.669  3804.877       1917.310
2   Control   M  7986.696  5377.977       2761.949
3   Control   M  8617.410  4443.345       2335.244
4   Control   M  7785.355  4307.021       2381.512
5   Control   M  9159.720  5568.449       3163.232
6   Control   M  8484.327  5314.041       3238.861
7   Control   M 10315.521  6105.294       3429.906
8   Control   M  5517.161  3090.970       1878.288
9      Cre-   M  6075.166  3438.421       2147.758
10     Cre-   M  8947.698  5809.953       3744.117
11     Cre-   M  6677.471  4315.344       2113.502
12     Cre-   M  7616.932  4293.291       2763.791
13     Cre-   M  8191.464  4778.529       2159.007
14     Cre-   M  8549.339  6043.961       2922.295
15     Cre-   M 11057.196  6546.740       3771.891
16     Cre-   M  5911.768  3382.556       1754.674

This is what I would like it to look something like:

enter image description here

Any help is greatly appreciated!

0

1 Answer 1

0

In this approach, we pivot the three measurements into long-form data. We map the measurement names to the x-axis and their respective values along the y. Mapping the Genotypes to the fill aesthetic yields the pairs of columns.

library(tidyverse)

df %>%
  pivot_longer(c(Glom.Area, Glom.Tuft, Mesangial.Area)) %>%
  ggplot(aes(name, value, fill = Genotype)) +
  geom_col(position = position_dodge())

Created on 2023-06-15 with reprex v2.0.2

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.