I´m rather new to R, but I need to make a graph with several dotted lines, I´ve tried a couple of things, but nothing has worked so far.
My looks like this;
Distance´´´´Area´´´´Volume.all´´´´´´Volume.colonised
0-9 m´´´´´´´´´´´´1´´´´ ´´´´´´7804.199 ´´´´´´´´250.05
10-19 m ´´´´´´ 1´´´´ ´´ 1320.086 ´´´´´´ 429.9361
20-29 m ´´´´´´ 1 ´´´´´´´´2342.75´´´´´´´´´´´´ 0
and so on...
I want to make a graph with the distance classes on the x-axes, and a dotted line each for; Volume colonised from area 1 Volume all from area 1 Volume colonised from area 2 Volume all from area 2
Very grateful for help!
You should bring your data in long format with pivot_longer
then ggplot
with group=names, color = names
library(tidyverse)
# dataframe
df <- tribble(
~Distance, ~Area, ~Volume.all, ~Volume.colonised,
"0-9 m", 1, 7804.199, 250.05,
"10-19 m", 1, 1320.086, 429.9361,
"20-29 m", 1, 2342.75, 0)
# long format
df1 <- df %>%
pivot_longer(
cols = contains("Volume"),
names_to = "names",
values_to = "values"
)
# plot
ggplot(df1, aes(x=Distance, y=values, group=names, color = names)) +
geom_line() +
geom_point()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.