Reputation: 75
I have gathered the data consisting of estimations of 2 means. I would like to draw ggplot (points connected with lines), where
I started like this, but I don't know why when I put the iterations on x axis, the mean is only one point. Below is how the data frame looks and my code. Thank you for help!
> frame
mu_1 mu_2 iteracje
1 0.9865904 7.005866 1
2 0.9865904 7.005866 2
3 0.9865904 7.005866 3
4 0.9865904 7.005866 4
5 0.9865904 7.005866 5
6 0.9865904 7.005866 6
7 0.9865904 7.005866 7
8 0.9865904 7.005866 8
9 0.9865904 7.005866 9
10 0.9865904 7.005866 10
frame = data.frame(mu_1, mu_2,iteracje=1:10)
ggplot(frame,aes(iteracje, mu_1))+geom_point(aes(mu_2))
Upvotes: 1
Views: 74
Reputation: 39613
Try this. The key is reshaping data to long and then plot:
library(dplyr)
library(tidyr)
library(ggplot2)
#Code
frame %>% pivot_longer(-iteracje) %>%
ggplot(aes(x=factor(iteracje),y=value,color=name,group=name))+
geom_point()+
geom_line()
Output:
Some data used:
#Data
frame <- structure(list(mu_1 = c(0.9865904, 0.9865904, 0.9865904, 0.9865904,
0.9865904, 0.9865904, 0.9865904, 0.9865904, 0.9865904, 0.9865904
), mu_2 = c(7.005866, 7.005866, 7.005866, 7.005866, 7.005866,
7.005866, 7.005866, 7.005866, 7.005866, 7.005866), iteracje = 1:10), class = "data.frame", row.names = c("1",
"2", "3", "4", "5", "6", "7", "8", "9", "10"))
Upvotes: 2