Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

How to add color in emmeans graph?

$
0
0

I would like to have one color for each level in x axis. I have tried different ways to enter the colour via col argument, but it doesn't seem to work. So far:

df <- structure(list(Scanner = structure(c(4L, 4L, 4L, 4L, 4L, 4L, 
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 5L, 5L, 
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 
6L, 6L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L), .Label = c("a", "b", "c", "d", "e", 
"f"), class = "factor"), Reta = structure(c(1L, 2L, 3L, 4L, 5L, 
6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 
4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 
2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 
6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 
4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 
2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 
6L, 1L, 2L, 3L, 4L, 5L, 6L), .Label = c("A", "B", "C", "D", "E", 
"F"), class = "factor"), erro = c(0.0120000000000005, 0.0289999999999999, 
0.088000000000001, 0.00600000000000023, -0.0289999999999964, 
0.106999999999999, 0.0850000000000009, 0.172999999999998, 0.183999999999997, 
0.208000000000006, 0.192, 0.0869999999999997, -0.0140000000000029, 
-0.0420000000000016, -0.0350000000000037, 0.00600000000000023, 
0, -0.0100000000000016, 0.167000000000002, 0.276, 0.262, 0.0790000000000006, 
0.426000000000002, 0.202999999999999, -0.181000000000004, 0.0560000000000009, 
-0.0219999999999985, -0.264999999999993, 0.106000000000002, 0.154999999999998, 
-0.0420000000000016, 0.0670000000000002, 0.176000000000002, -0.18, 
0.215000000000003, 0.189, -0.036999999999999, 0.169, 0.103000000000002, 
-0.622999999999998, 0.268999999999998, 0.106999999999999, -0.0140000000000029, 
0.169999999999998, 0.115000000000002, -0.622, 0.276000000000003, 
0.0969999999999978, -0.0320000000000036, 0.155999999999999, 0.116, 
-0.290999999999997, 0.283000000000001, 0.0439999999999969, 0.0940000000000012, 
-0.117000000000001, 0.0249999999999986, 0.00900000000000034, 
0.0760000000000005, 0.109999999999999, 0.0549999999999997, 0.0470000000000006, 
-0.027000000000001, 0.0130000000000052, 0.036999999999999, 0.0139999999999993, 
0.0420000000000016, 0.0459999999999994, -0.109999999999999, 0.007000000000005, 
0.0339999999999989, 0.104999999999997, -0.240000000000002, 0.0940000000000012, 
-0.0570000000000022, -0.352999999999994, 0.0129999999999981, 
0.113, -0.251000000000005, 0.0760000000000005, -0.00200000000000244, 
NA, 0.112000000000002, 0.0839999999999996, -0.242000000000004, 
0.0530000000000008, -0.134999999999998, -0.446999999999996, 0.118000000000002, 
0.075999999999997, -0.0769999999999982, -0.0590000000000011, 
-0.0870000000000033, -0.445999999999998, 0.158999999999999, 0.0829999999999984, 
-0.270000000000003, -0.0210000000000008, -0.0840000000000032, 
-0.189999999999998, 0.116999999999997, 0.0519999999999996, -0.0960000000000036, 
-0.0859999999999985, -0.177, -0.271999999999998, 0.0679999999999978, 
0.0439999999999969)), row.names = c(NA, -108L), class = c("tbl_df", 
"tbl", "data.frame"))
m1 <- lm(erro ~ Scanner*Reta, data = df)
l1 <- emmeans(m1, "Scanner", "Reta")
emmip(l1, ~ Reta |Scanner, 
      col = rep(cols, each = 108/6),
      CIs = TRUE) +
  geom_hline(yintercept = 0, linetype = 2) +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
  labs(y = "Erro absoluto (mm)")

enter image description here


Viewing all articles
Browse latest Browse all 201839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>