# What type of graph should I use?

Hi people!I need help with my doctoral data. I have a problem with the scale of the data and I don't know how to represent it. It is abundance dating and I need to compare two years.

F1=c(Deposit,Filter,Herbivore,Grazer,Predator)
2001=c(56,78,45,5,63)
2021=c(2708,2681,15,0 ,1742)

I hope you can help me!
Grace.

It would help to have a bit more information about what you want to know but the most obvious start is probably a barchart

I used the `data.table` package to make the example so you probably will need to do

``````install.packages("data.table)
``````

before running the code below

``````## load required libraries
library(data.table)
library(ggplot2)

# Wrangle data into a data.table.

dat1 <- data.table(f1 = c("Deposit","Filter","Herbivore","Grazer","Predator"),
y2001 = c(56, 78, 45, 5, 63),
y2021 = c(2708, 2681, 15, 0, 1742)
)

# Convert data from *wide* to *long* form.
dat2 <- melt.data.table(dat1, id.vars = "f1", measure.vars = c("y2001", "y2021"),
variable.name = "Year", value.name = "Result")

# plot data.
ggplot(dat2, aes(f1, Result,  fill  = Year)) + geom_col(position = "jitter", width = .5)

``````

If you prefer the tidyverse approach you can get the same results with

``````dat <- dat1  %>%  pivot_longer(!f1, names_to = "Year", values_to = "Result")

ggplot(dat, aes(f1, Result,  fill  = Year)) + geom_col(position = "jitter", width = .5)
``````

building on jrkrideau you could experiment with going from

``````ggplot(dat2, aes(f1, Result,  fill  = Year)) +
geom_col(position = "jitter", width = .5)
``````

to

by

``````ggplot(dat2, aes(f1, Result,  fill  = Year)) +
geom_col(position = "jitter", width = .5) +
facet_wrap(~Year,scales = "free") +
scale_fill_discrete(guide=guide_none())``````
1 Like

A better idea in some ways but the `scales = "free"` worries me. We lose the dramatic contrast across years. Something has really changed in that decade. The grazers and herbivores are are taking a real hit. Both plots in a results section may make sense.

My idea is to compare what happened between 2001 and 2021 with the feeding mode of some organisms. I made the same graph as you but you can't see 2001 because of the jump in scale. There are bar graphs where you can cut the scale but I don't know how to make them.
Anyway thanks for your help @nirgrahamuk !

My idea is to compare what happened between 2001 and 2021 with the feeding mode of some organisms. I will try to run what you sent me. I would like to make a bar graph but cut the scale so that the 2001 data can be seen.

``````library(ggbreak) # https://github.com/YuLab-SMU/ggbreak
ggplot(dat2, aes(f1, Result,  fill  = Year)) +
geom_col(position = "dodge") +
scale_y_break(breaks=c(100,1500),
scales = .7)
``````

1 Like

You're a genius! It's just what I needed.
Thank you so much!

It might be a better idea to plot the two years separately and stack them one top of one another.

``````library(data.table)
library(ggplot2)
library(patchwork)

dat1 <- data.table(f1 = c("Deposit","Filter","Herbivore","Grazer","Predator"),
y2001 = c(56, 78, 45, 5, 63),
y2021 = c(2708, 2681, 15, 0, 1742)
)

p1 <- ggplot(dat1, aes(f1, y2001)) +
geom_col(fill = "dark green", width = .3) +
geom_text(x=4, y= 70, label="2001", size = 6) +
ylab("Results") + xlab("Monsters")
theme(legend.position="none")

p2 <- ggplot(dat1, aes(f1, y2021)) +
geom_col(fill = "blue", width = .3) +
geom_text(x=4, y= 2500, label="2021", size = 6) +
ylab("Results") + xlab("Monsters") +
theme(legend.position="none")

p1 + p2 + plot_layout(nrow = 2)

``````

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.