I have a data frame with the intercepts and slopes for six lines. There are other questions that address this (i.e., this question), but when I follow the same approach, it doesn't seem to work.
When I try the following, a plot with only a single line is returned:
library(ggplot2)
library(tibble)
d <- tibble::tribble(
~ID, ~b0, ~b1,
1L, -0.253642820580212, 0.0388815148531228,
2L, -0.247859980353316, 0.0462798786249876,
3L, -0.241628306421253, 0.0418616653609702,
4L, -0.476161762130615, 0.0216251842526953,
5L, -0.372079433686108, 0.0564612163378217,
6L, -0.0983318344106016, 0.0759661386473856
)
ggplot(d, aes(intercept = b0, slope = b1)) +
geom_abline() +
xlim(0, 10) +
ylim(0, 10)

How can I plot the six lines associated with the six intercepts and slopes?
ggplot(d) +
geom_abline(aes(intercept = b0, slope = b1, color=factor(ID))) +
xlim(0, 100) +
ylim(0, 10)

Here is what I would do:
library(tibble)
d <- tibble::tribble(
~ID, ~b0, ~b1,
1L, -0.253642820580212, 0.0388815148531228,
2L, -0.247859980353316, 0.0462798786249876,
3L, -0.241628306421253, 0.0418616653609702,
4L, -0.476161762130615, 0.0216251842526953,
5L, -0.372079433686108, 0.0564612163378217,
6L, -0.0983318344106016, 0.0759661386473856
)
ggplot(d) +
geom_abline(aes(intercept = b0, slope = b1, group = "ID")) +
xlim(0, 10) +
ylim(0, 10)
Not sure about the limits though
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With