Quantizer
Quantizer

Reputation: 297

Make one plot with multiple models (same B_0 but different B_1) using ggplot2

Does any of you know how to combine several plots into one. The slope is different for each plot, but the intercept the same (it is a linear plot). The idea is something like this: https://i.sstatic.net/wEZ7z.jpg

influ_betaHat  alphaHat
3.227066       46.24765
2.960255       46.24765
3.102799       46.24765
2.828902       46.24765
3.313600       46.24765
2.745708       46.24765
3.042078       46.24765
3.023972       46.24765
2.968079       46.24765
3.050344       46.24765
3.008462       46.24765
3.231354       46.24765
3.115002       46.24765
3.058765       46.24765
3.043138       46.24765
3.162286       46.24765

Upvotes: 0

Views: 59

Answers (1)

Jon Spring
Jon Spring

Reputation: 66415

One key thing here is that you have to establish the "viewing window" with coord_cartesian, since the lines themselves cover an infinite range of values.

library(ggplot2)
ggplot(my_data) +
  geom_abline(aes(slope = influ_betaHat, intercept = alphaHat)) +
  scale_y_continuous(breaks = 46) +
  scale_x_continuous(breaks = 10*(0:5)) +
  geom_hline(yintercept = 0) +
  geom_vline(xintercept = 0) +
  coord_cartesian(ylim = c(0, 100), xlim = c(0, 50)) +
  theme_minimal()

enter image description here

Upvotes: 1

Related Questions