data.frame(
S = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L),
Beta = c(0.52, 0.641, 0.677, 0.627, 0.603, 0.436, 0.5, 0.366, 0.718),
Tur = c(0.307, 0.461, 0.23, 0.62, 0.6, 0.431, 0.269, 0.346, 0.307),
Ned = c(0.213, 0.182, 0.447, 0.007, 0.003, 0.005, 0.231, 0.02, 0.411)
#This is what I did and I can't do it!
b<-ggplot(data.frame,aes(x=S, fill=Beta,Tur,Ned)) +
geom_blank(stat="identity")+ theme_classic()
Something like this?
library(tidyverse)
df <- data.frame(
S = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L),
Beta = c(0.52, 0.641, 0.677, 0.627, 0.603, 0.436, 0.5, 0.366, 0.718),
Tur = c(0.307, 0.461, 0.23, 0.62, 0.6, 0.431, 0.269, 0.346, 0.307),
Ned = c(0.213, 0.182, 0.447, 0.007, 0.003, 0.005, 0.231, 0.02, 0.411))
df %>%
pivot_longer(Beta:Ned, names_to = "Parameter", values_to = "Value") %>%
mutate(S = factor(S)) %>%
ggplot(aes(x=S, y = Value, fill=Parameter)) +
geom_col(position = "dodge") +
theme_classic()
Created on 2021-09-02 by the reprex package (v2.0.1)
It is exactly what I was looking for ... thanks for your help!
R does not recognize me neither the function "pivot_longer" nor%>%.Do I have to install any packages before?
Install and load the tidyverse
package (or at least ggplot2
, dplyr
and tidyr
which are part of the tidyverse
)
This topic was automatically closed 21 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.