1

Two variables plot together when plotting by "Case" N, can I separate them so they plot with two different lines?

See green dots have two values per x-Sample and are plotted as same green line.

data <- tibble::tibble(
  value = c(0.0693, 0.0677, 0.0727, 0.0650, 0.0908, 0.00112,    0.131,  0.0975, 0.109,  0.105,  0.0927, 0.0552, 0.0532, 0.0559, 0.0771, 0.0563, 0.0551,
0.191,  0.193,  0.147,  0.157,  0.258,  0.00738,    0.00808,    0.00661,    0.00495210983601696,    0.451,  0.379,  0.0653, 0.0350, 0.0559, 0.192,  0.0738, 0.107,
0.0138, 0.0104, 0.0145, 0.0103, 5.08255237961193E-05,   0.0361, 0.0264, 0.0454, 0.0277, 0.0117, 8.92140244446427E-05,   0.0173727368061961, 0.0108, 8.54627809588924E-05,   2.35593459925552E-05,   3.13020069803476E-05,   1.12019464502152E-05, 
0.0453, 0.0577, 0.0627, 0.0450, 0.0508, 0.00212,    0.031,  0.0875, 0.100,  0.115,  0.0827, 0.0452, 0.0332, 0.0459, 0.0671, 0.0263, 0.0451), 
Sample = rep(c(1:17),4),
Variable = rep(c(paste0("A",rep(1:4))),17),
Case = rep(c("P",rep("N",2),"L" ), 17))

ggplot(data, aes(x=Sample, y=value, color=Case)) + 
  geom_line() +
 geom_point()

enter image description here

1 Answer 1

1

You can use group = interaction(Variable, Cases):

ggplot(data, aes(x=Sample, y=value, color=Case, group = interaction(Variable,Case))) + 
  geom_line() +
  geom_point()

enter image description here

If you want different colors for each you can pass color = interaction(Varaible, Case).

Does it answer your question ?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.