invalid color name background in qgraph - r
I have been trying to use qgraph to generate the network graph. The code is as following
Gw <- qgraph(edgeList, diag = TRUE, labels = TRUE,legend.cex = 0.3, vsize = 1,edge.color=colorLabels,legend=TRUE,asize=1)
The figure can be generated, but the R command line gives the following error message. I do not know what does the invalid color name 'background' mean.
The dput result is shown as follows,
dput(edgeList)
structure(c("1", "2", "2", "3", "4", "5", "6", "7", "8", "1",
"9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "16",
"4", "5", "7", "1", "9", "10", "19", "20", "2", "16", "21", "3",
"22", "5", "23", "8", "1", "20", "2", "13", "14", "17", "14",
"1", "19", "14", "2", "21", "14", "24", "1", ":499.3", "nk Transfe",
"de of tran", "up(non-US ", "up(non-US ", "up(non-US ", "up(non-US ",
"up(non-US ", "up(non-US ", "up(non-US ", "up(non-US ", "up(non-US ",
"ine:4121", "ine:3257.4", "ine:75.2", "ine:75.2", "ine:11615.",
"ine:10603", "ine:334.2", "ine:7256.8", "ine:7256.8", "ine:996.8",
"ine:884.6", "ine:364.9", "ine:6360", "ine:5640.9", "ine:2729.7",
"ine:5482.6", "ine:85", "ine:1474.9", "ine:700.8", "ine:2754.6",
"ine:3257.4", "ine:3257.4", "ine:7307.8", "ine:18560.", "ine:85.1",
"ine:364.8", ":700.1", ":5317", "l:4258.9", "l:4258.9", "l:1637.6",
"l:1637.6", "l:46.4", "l:3938.5", "l:3938.5", "l:2800.4", "l:2715.1",
"l:2715.1", "l:12708.2", "l:1042", ":499.3", "nk Transfe", "de of tran",
"up(non-US ", "up(non-US ", "up(non-US ", "up(non-US ", "up(non-US ",
"up(non-US ", "up(non-US ", "up(non-US ", "up(non-US ", "ine:4121",
"ine:3257.4", "ine:75.2", "ine:75.2", "ine:11615.", "ine:10603",
"ine:334.2", "ine:7256.8", "ine:7256.8", "ine:996.8", "ine:884.6",
"ine:364.9", "ine:6360", "ine:5640.9", "ine:2729.7", "ine:5482.6",
"ine:85", "ine:1474.9", "ine:700.8", "ine:2754.6", "ine:3257.4",
"ine:3257.4", "ine:7307.8", "ine:18560.", "ine:85.1", "ine:364.8",
":700.1", ":5317", "l:4258.9", "l:4258.9", "l:1637.6", "l:1637.6",
"l:46.4", "l:3938.5", "l:3938.5", "l:2800.4", "l:2715.1", "l:2715.1",
"l:12708.2", "l:1042", "25", "1", "1", "26", "27", "28", "29",
"30", "31", "25", "32", "33", "4", "4", "3", "3", "5", "5", "7",
"6", "6", "27", "28", "30", "25", "32", "33", "9", "8", "1",
"1", "10", "12", "12", "16", "16", "16", "16", "8", "1", "3",
"3", "7", "7", "25", "9", "9", "1", "10", "10", "14", "14"), .Dim = c(104L,
2L), .Dimnames = list(NULL, c("newsendId", "newtoId")))
The generated figure is as follows. I used the following command to generate it
Gw <- qgraph(edgeList, layout = "spring", diag = FALSE, labels = TRUE, cut = NULL, edge.color = "red",legend.cex = 0.5, vsize = 8)
Which nodes are problems? With your data and code you can modify label.cex. There are other variations of the arguments for the label and legend sizes. Here is one version, with the color blue.
library(qgraph)
Gw <- qgraph(edgeList, layout = "spring", diag = FALSE, labels = TRUE, cut = NULL, edge.color = "red", legend.cex = 0.3, vsize = 4, label.cex = 0.3, label.color = "blue")
Gw
Related
Recode a factor variable, dropping N/A
I have a factor variable with 14 levels, which I'm trying to into collapse into only 3 levels. It contains two N/A which I also wanna remove. My code looks like this: job <- fct_collapse(E$occupation, other = c("7","9", "10", "13" "14"), 1 = c("1", "2", "3", "12"), 2 = c("4", "5", "6", "8", "11")) However it just gives me tons of error. Can anyone help here me here?
We could also this with a named list library(forcats) lst1 <- setNames(list(as.character(c(7, 9, 10, 13, 14)), as.character(c(1, 2, 3, 12)), as.character(c(4, 5, 6, 8, 11))), c('other', 1, 2)) fct_collapse(df$occupation, !!!lst1) data df <- structure(list(occupation = c("1", "3", "5", "7", "9", "10", "12", "14", "13", "4", "7", "6", "5")), class = "data.frame", row.names = c(NA, -13L))
For numbers try using backquotes in fct_collapse. job <- forcats::fct_collapse(df$occupation, other = c("7","9", "10", "13", "14"), `1` = c("1", "2", "3", "12"), `2` = c("4", "5", "6", "8", "11"))
scale_x_continuous : Discrete value supplied to continuous scale
I'm a beginner in R. I get this error Error: Discrete value supplied to continuous scale when I try to use scale_x_continuous(breaks=1:10) The plot I get is the following one. As you can see, the axis needs to be reduced... I get my data from a csv file dput(head(Data, 20)) structure(list(Pmanche = structure(1:20, .Label = c("0", "0,1", "0,2", "0,3", "0,4", "0,5", "0,6", "0,7", "0,8", "0,9", "1", "1,1", "1,2", "1,3", "1,4", "1,5", "1,6", "1,7", "1,8", "1,9", "10", "10,1", "10,2", "10,3", "10,4", "10,5", "10,6", "10,7", "10,8", "10,9", "100", "11", "11,1", "11,2", "11,3", "11,4", "11,5", "11,6", "11,7", "11,8", "11,9", "12", "12,1", "12,2", "12,3", "12,4", "12,5", "12,6", "12,7", "12,8", "12,9", "13", "13,1", "13,2", "13,3", "13,4", "13,5", "13,6", "13,7", "13,8", "13,9", "14", "14,1", "14,2", "14,3", "14,4", "14,5", "14,6", "14,7", "14,8", "14,9", "15", "15,1", "15,2", "15,3", "15,4", "15,5", "15,6", "15,7", "15,8", "15,9", "16", "16,1", "16,2", "16,3", "16,4", "16,5", "16,6", "16,7", "16,8", "16,9", "17", "17,1", "17,2", "17,3", "17,4", "17,5", "17,6", "17,7", "17,8", "17,9", "18", "18,1", "18,2", "18,3", "18,4", "18,5", "18,6", "18,7", "18,8", "18,9", "19", "19,1", "19,2", "19,3", "19,4", "19,5", "19,6", "19,7", "19,8", "19,9", "2", "2,1", "2,2", "2,3", "2,4", "2,5", "2,6", "2,7", "2,8", "2,9", "20", "20,1", "20,2", "20,3", "20,4", "20,5", "20,6", "20,7", "20,8", "20,9", "21", "21,1", "21,2", "21,3", "21,4", "21,5", "21,6", "21,7", "21,8", "21,9", "22", "22,1", "22,2", "22,3", "22,4", "22,5", "22,6", "22,7", "22,8", "22,9", "23", "23,1", "23,2", "23,3", "23,4", "23,5", "23,6", "23,7", "23,8", "23,9", "24", "24,1", "24,2", "24,3", "24,4", "24,5", "24,6", "24,7", "24,8", "24,9", "25", "25,1", "25,2", "25,3", "25,4", "25,5", "25,6", "25,7", "25,8", "25,9", "26", "26,1", "26,2", "26,3", "26,4", "26,5", "26,6", "26,7", "26,8", "26,9", "27", "27,1", "27,2", "27,3", "27,4", "27,5", "27,6", "27,7", "27,8", "27,9", "28", "28,1", "28,2", "28,3", "28,4", "28,5", "28,6", "28,7", "28,8", "28,9", "29", "29,1", "29,2", "29,3", "29,4", "29,5", "29,6", "29,7", "29,8", "29,9", "3", "3,1", "3,2", "3,3", "3,4", "3,5", "3,6", "3,7", "3,8", "3,9", "30", "30,1", "30,2", "30,3", "30,4", "30,5", "30,6", "30,7", "30,8", "30,9", "31", "31,1", "31,2", "31,3", "31,4", "31,5", "31,6", "31,7", "31,8", "31,9", "32", "32,1", "32,2", "32,3", "32,4", "32,5", "32,6", "32,7", "32,8", "32,9", "33", "33,1", "33,2", "33,3", "33,4", "33,5", "33,6", "33,7", "33,8", "33,9", "34", "34,1", "34,2", "34,3", "34,4", "34,5", "34,6", "34,7", "34,8", "34,9", "35", "35,1", "35,2", "35,3", "35,4", "35,5", "35,6", "35,7", "35,8", "35,9", "36", "36,1", "36,2", "36,3", "36,4", "36,5", "36,6", "36,7", "36,8", "36,9", "37", "37,1", "37,2", "37,3", "37,4", "37,5", "37,6", "37,7", "37,8", "37,9", "38", "38,1", "38,2", "38,3", "38,4", "38,5", "38,6", "38,7", "38,8", "38,9", "39", "39,1", "39,2", "39,3", "39,4", "39,5", "39,6", "39,7", "39,8", "39,9", "4", "4,1", "4,2", "4,3", "4,4", "4,5", "4,6", "4,7", "4,8", "4,9", "40", "40,1", "40,2", "40,3", "40,4", "40,5", "40,6", "40,7", "40,8", "40,9", "41", "41,1", "41,2", "41,3", "41,4", "41,5", "41,6", "41,7", "41,8", "41,9", "42", "42,1", "42,2", "42,3", "42,4", "42,5", "42,6", "42,7", "42,8", "42,9", "43", "43,1", "43,2", "43,3", "43,4", "43,5", "43,6", "43,7", "43,8", "43,9", "44", "44,1", "44,2", "44,3", "44,4", "44,5", "44,6", "44,7", "44,8", "44,9", "45", "45,1", "45,2", "45,3", "45,4", "45,5", "45,6", "45,7", "45,8", "45,9", "46", "46,1", "46,2", "46,3", "46,4", "46,5", "46,6", "46,7", "46,8", "46,9", "47", "47,1", "47,2", "47,3", "47,4", "47,5", "47,6", "47,7", "47,8", "47,9", "48", "48,1", "48,2", "48,3", "48,4", "48,5", "48,6", "48,7", "48,8", "48,9", "49", "49,1", "49,2", "49,3", "49,4", "49,5", "49,6", "49,7", "49,8", "49,9", "5", "5,1", "5,2", "5,3", "5,4", "5,5", "5,6", "5,7", "5,8", "5,9", "50", "50,1", "50,2", "50,3", "50,4", "50,5", "50,6", "50,7", "50,8", "50,9", "51", "51,1", "51,2", "51,3", "51,4", "51,5", "51,6", "51,7", "51,8", "51,9", "52", "52,1", "52,2", "52,3", "52,4", "52,5", "52,6", "52,7", "52,8", "52,9", "53", "53,1", "53,2", "53,3", "53,4", "53,5", "53,6", "53,7", "53,8", "53,9", "54", "54,1", "54,2", "54,3", "54,4", "54,5", "54,6", "54,7", "54,8", "54,9", "55", "55,1", "55,2", "55,3", "55,4", "55,5", "55,6", "55,7", "55,8", "55,9", "56", "56,1", "56,2", "56,3", "56,4", "56,5", "56,6", "56,7", "56,8", "56,9", "57", "57,1", "57,2", "57,3", "57,4", "57,5", "57,6", "57,7", "57,8", "57,9", "58", "58,1", "58,2", "58,3", "58,4", "58,5", "58,6", "58,7", "58,8", "58,9", "59", "59,1", "59,2", "59,3", "59,4", "59,5", "59,6", "59,7", "59,8", "59,9", "6", "6,1", "6,2", "6,3", "6,4", "6,5", "6,6", "6,7", "6,8", "6,9", "60", "60,1", "60,2", "60,3", "60,4", "60,5", "60,6", "60,7", "60,8", "60,9", "61", "61,1", "61,2", "61,3", "61,4", "61,5", "61,6", "61,7", "61,8", "61,9", "62", "62,1", "62,2", "62,3", "62,4", "62,5", "62,6", "62,7", "62,8", "62,9", "63", "63,1", "63,2", "63,3", "63,4", "63,5", "63,6", "63,7", "63,8", "63,9", "64", "64,1", "64,2", "64,3", "64,4", "64,5", "64,6", "64,7", "64,8", "64,9", "65", "65,1", "65,2", "65,3", "65,4", "65,5", "65,6", "65,7", "65,8", "65,9", "66", "66,1", "66,2", "66,3", "66,4", "66,5", "66,6", "66,7", "66,8", "66,9", "67", "67,1", "67,2", "67,3", "67,4", "67,5", "67,6", "67,7", "67,8", "67,9", "68", "68,1", "68,2", "68,3", "68,4", "68,5", "68,6", "68,7", "68,8", "68,9", "69", "69,1", "69,2", "69,3", "69,4", "69,5", "69,6", "69,7", "69,8", "69,9", "7", "7,1", "7,2", "7,3", "7,4", "7,5", "7,6", "7,7", "7,8", "7,9", "70", "70,1", "70,2", "70,3", "70,4", "70,5", "70,6", "70,7", "70,8", "70,9", "71", "71,1", "71,2", "71,3", "71,4", "71,5", "71,6", "71,7", "71,8", "71,9", "72", "72,1", "72,2", "72,3", "72,4", "72,5", "72,6", "72,7", "72,8", "72,9", "73", "73,1", "73,2", "73,3", "73,4", "73,5", "73,6", "73,7", "73,8", "73,9", "74", "74,1", "74,2", "74,3", "74,4", "74,5", "74,6", "74,7", "74,8", "74,9", "75", "75,1", "75,2", "75,3", "75,4", "75,5", "75,6", "75,7", "75,8", "75,9", "76", "76,1", "76,2", "76,3", "76,4", "76,5", "76,6", "76,7", "76,8", "76,9", "77", "77,1", "77,2", "77,3", "77,4", "77,5", "77,6", "77,7", "77,8", "77,9", "78", "78,1", "78,2", "78,3", "78,4", "78,5", "78,6", "78,7", "78,8", "78,9", "79", "79,1", "79,2", "79,3", "79,4", "79,5", "79,6", "79,7", "79,8", "79,9", "8", "8,1", "8,2", "8,3", "8,4", "8,5", "8,6", "8,7", "8,8", "8,9", "80", "80,1", "80,2", "80,3", "80,4", "80,5", "80,6", "80,7", "80,8", "80,9", "81", "81,1", "81,2", "81,3", "81,4", "81,5", "81,6", "81,7", "81,8", "81,9", "82", "82,1", "82,2", "82,3", "82,4", "82,5", "82,6", "82,7", "82,8", "82,9", "83", "83,1", "83,2", "83,3", "83,4", "83,5", "83,6", "83,7", "83,8", "83,9", "84", "84,1", "84,2", "84,3", "84,4", "84,5", "84,6", "84,7", "84,8", "84,9", "85", "85,1", "85,2", "85,3", "85,4", "85,5", "85,6", "85,7", "85,8", "85,9", "86", "86,1", "86,2", "86,3", "86,4", "86,5", "86,6", "86,7", "86,8", "86,9", "87", "87,1", "87,2", "87,3", "87,4", "87,5", "87,6", "87,7", "87,8", "87,9", "88", "88,1", "88,2", "88,3", "88,4", "88,5", "88,6", "88,7", "88,8", "88,9", "89", "89,1", "89,2", "89,3", "89,4", "89,5", "89,6", "89,7", "89,8", "89,9", "9", "9,1", "9,2", "9,3", "9,4", "9,5", "9,6", "9,7", "9,8", "9,9", "90", "90,1", "90,2", "90,3", "90,4", "90,5", "90,6", "90,7", "90,8", "90,9", "91", "91,1", "91,2", "91,3", "91,4", "91,5", "91,6", "91,7", "91,8", "91,9", "92", "92,1", "92,2", "92,3", "92,4", "92,5", "92,6", "92,7", "92,8", "92,9", "93", "93,1", "93,2", "93,3", "93,4", "93,5", "93,6", "93,7", "93,8", "93,9", "94", "94,1", "94,2", "94,3", "94,4", "94,5", "94,6", "94,7", "94,8", "94,9", "95", "95,1", "95,2", "95,3", "95,4", "95,5", "95,6", "95,7", "95,8", "95,9", "96", "96,1", "96,2", "96,3", "96,4", "96,5", "96,6", "96,7", "96,8", "96,9", "97", "97,1", "97,2", "97,3", "97,4", "97,5", "97,6", "97,7", "97,8", "97,9", "98", "98,1", "98,2", "98,3", "98,4", "98,5", "98,6", "98,7", "98,8", "98,9", "99", "99,1", "99,2", "99,3", "99,4", "99,5", "99,6", "99,7", "99,8", "99,9"), class = "factor"), Pcsge = structure(1:20, .Label = c("0", "0,1", "0,2", "0,3", "0,4", "0,5", "0,6", "0,7", "0,8", "0,9", "1", "1,1", "1,2", "1,3", "1,4", "1,5", "1,6", "1,7", "1,8", "1,9", "10", "10,1", "10,2", "10,3", "10,4", "10,5", "10,6", "10,7", "10,8", "10,9", "100", "11", "11,1", "11,2", "11,3", "11,4", "11,5", "11,6", "11,7", "11,8", "11,9", "12", "12,1", "12,2", "12,3", "12,4", "12,5", "12,6", "12,7", "12,8", "12,9", "13", "13,1", "13,2", "13,3", "13,4", "13,5", "13,6", "13,7", "13,8", "13,9", "14", "14,1", "14,2", "14,3", "14,4", "14,5", "14,6", "14,7", "14,8", "14,9", "15", "15,1", "15,2", "15,3", "15,4", "15,5", "15,6", "15,7", "15,8", "15,9", "16", "16,1", "16,2", "16,3", "16,4", "16,5", "16,6", "16,7", "16,8", "16,9", "17", "17,1", "17,2", "17,3", "17,4", "17,5", "17,6", "17,7", "17,8", "17,9", "18", "18,1", "18,2", "18,3", "18,4", "18,5", "18,6", "18,7", "18,8", "18,9", "19", "19,1", "19,2", "19,3", "19,4", "19,5", "19,6", "19,7", "19,8", "19,9", "2", "2,1", "2,2", "2,3", "2,4", "2,5", "2,6", "2,7", "2,8", "2,9", "20", "20,1", "20,2", "20,3", "20,4", "20,5", "20,6", "20,7", "20,8", "20,9", "21", "21,1", "21,2", "21,3", "21,4", "21,5", "21,6", "21,7", "21,8", "21,9", "22", "22,1", "22,2", "22,3", "22,4", "22,5", "22,6", "22,7", "22,8", "22,9", "23", "23,1", "23,2", "23,3", "23,4", "23,5", "23,6", "23,7", "23,8", "23,9", "24", "24,1", "24,2", "24,3", "24,4", "24,5", "24,6", "24,7", "24,8", "24,9", "25", "25,1", "25,2", "25,3", "25,4", "25,5", "25,6", "25,7", "25,8", "25,9", "26", "26,1", "26,2", "26,3", "26,4", "26,5", "26,6", "26,7", "26,8", "26,9", "27", "27,1", "27,2", "27,3", "27,4", "27,5", "27,6", "27,7", "27,8", "27,9", "28", "28,1", "28,2", "28,3", "28,4", "28,5", "28,6", "28,7", "28,8", "28,9", "29", "29,1", "29,2", "29,3", "29,4", "29,5", "29,6", "29,7", "29,8", "29,9", "3", "3,1", "3,2", "3,3", "3,4", "3,5", "3,6", "3,7", "3,8", "3,9", "30", "30,1", "30,2", "30,3", "30,4", "30,5", "30,6", "30,7", "30,8", "30,9", "31", "31,1", "31,2", "31,3", "31,4", "31,5", "31,6", "31,7", "31,8", "31,9", "32", "32,1", "32,2", "32,3", "32,4", "32,5", "32,6", "32,7", "32,8", "32,9", "33", "33,1", "33,2", "33,3", "33,4", "33,5", "33,6", "33,7", "33,8", "33,9", "34", "34,1", "34,2", "34,3", "34,4", "34,5", "34,6", "34,7", "34,8", "34,9", "35", "35,1", "35,2", "35,3", "35,4", "35,5", "35,6", "35,7", "35,8", "35,9", "36", "36,1", "36,2", "36,3", "36,4", "36,5", "36,6", "36,7", "36,8", "36,9", "37", "37,1", "37,2", "37,3", "37,4", "37,5", "37,6", "37,7", "37,8", "37,9", "38", "38,1", "38,2", "38,3", "38,4", "38,5", "38,6", "38,7", "38,8", "38,9", "39", "39,1", "39,2", "39,3", "39,4", "39,5", "39,6", "39,7", "39,8", "39,9", "4", "4,1", "4,2", "4,3", "4,4", "4,5", "4,6", "4,7", "4,8", "4,9", "40", "40,1", "40,2", "40,3", "40,4", "40,5", "40,6", "40,7", "40,8", "40,9", "41", "41,1", "41,2", "41,3", "41,4", "41,5", "41,6", "41,7", "41,8", "41,9", "42", "42,1", "42,2", "42,3", "42,4", "42,5", "42,6", "42,7", "42,8", "42,9", "43", "43,1", "43,2", "43,3", "43,4", "43,5", "43,6", "43,7", "43,8", "43,9", "44", "44,1", "44,2", "44,3", "44,4", "44,5", "44,6", "44,7", "44,8", "44,9", "45", "45,1", "45,2", "45,3", "45,4", "45,5", "45,6", "45,7", "45,8", "45,9", "46", "46,1", "46,2", "46,3", "46,4", "46,5", "46,6", "46,7", "46,8", "46,9", "47", "47,1", "47,2", "47,3", "47,4", "47,5", "47,6", "47,7", "47,8", "47,9", "48", "48,1", "48,2", "48,3", "48,4", "48,5", "48,6", "48,7", "48,8", "48,9", "49", "49,1", "49,2", "49,3", "49,4", "49,5", "49,6", "49,7", "49,8", "49,9", "5", "5,1", "5,2", "5,3", "5,4", "5,5", "5,6", "5,7", "5,8", "5,9", "50", "50,1", "50,2", "50,3", "50,4", "50,5", "50,6", "50,7", "50,8", "50,9", "51", "51,1", "51,2", "51,3", "51,4", "51,5", "51,6", "51,7", "51,8", "51,9", "52", "52,1", "52,2", "52,3", "52,4", "52,5", "52,6", "52,7", "52,8", "52,9", "53", "53,1", "53,2", "53,3", "53,4", "53,5", "53,6", "53,7", "53,8", "53,9", "54", "54,1", "54,2", "54,3", "54,4", "54,5", "54,6", "54,7", "54,8", "54,9", "55", "55,1", "55,2", "55,3", "55,4", "55,5", "55,6", "55,7", "55,8", "55,9", "56", "56,1", "56,2", "56,3", "56,4", "56,5", "56,6", "56,7", "56,8", "56,9", "57", "57,1", "57,2", "57,3", "57,4", "57,5", "57,6", "57,7", "57,8", "57,9", "58", "58,1", "58,2", "58,3", "58,4", "58,5", "58,6", "58,7", "58,8", "58,9", "59", "59,1", "59,2", "59,3", "59,4", "59,5", "59,6", "59,7", "59,8", "59,9", "6", "6,1", "6,2", "6,3", "6,4", "6,5", "6,6", "6,7", "6,8", "6,9", "60", "60,1", "60,2", "60,3", "60,4", "60,5", "60,6", "60,7", "60,8", "60,9", "61", "61,1", "61,2", "61,3", "61,4", "61,5", "61,6", "61,7", "61,8", "61,9", "62", "62,1", "62,2", "62,3", "62,4", "62,5", "62,6", "62,7", "62,8", "62,9", "63", "63,1", "63,2", "63,3", "63,4", "63,5", "63,6", "63,7", "63,8", "63,9", "64", "64,1", "64,2", "64,3", "64,4", "64,5", "64,6", "64,7", "64,8", "64,9", "65", "65,1", "65,2", "65,3", "65,4", "65,5", "65,6", "65,7", "65,8", "65,9", "66", "66,1", "66,2", "66,3", "66,4", "66,5", "66,6", "66,7", "66,8", "66,9", "67", "67,1", "67,2", "67,3", "67,4", "67,5", "67,6", "67,7", "67,8", "67,9", "68", "68,1", "68,2", "68,3", "68,4", "68,5", "68,6", "68,7", "68,8", "68,9", "69", "69,1", "69,2", "69,3", "69,4", "69,5", "69,6", "69,7", "69,8", "69,9", "7", "7,1", "7,2", "7,3", "7,4", "7,5", "7,6", "7,7", "7,8", "7,9", "70", "70,1", "70,2", "70,3", "70,4", "70,5", "70,6", "70,7", "70,8", "70,9", "71", "71,1", "71,2", "71,3", "71,4", "71,5", "71,6", "71,7", "71,8", "71,9", "72", "72,1", "72,2", "72,3", "72,4", "72,5", "72,6", "72,7", "72,8", "72,9", "73", "73,1", "73,2", "73,3", "73,4", "73,5", "73,6", "73,7", "73,8", "73,9", "74", "74,1", "74,2", "74,3", "74,4", "74,5", "74,6", "74,7", "74,8", "74,9", "75", "75,1", "75,2", "75,3", "75,4", "75,5", "75,6", "75,7", "75,8", "75,9", "76", "76,1", "76,2", "76,3", "76,4", "76,5", "76,6", "76,7", "76,8", "76,9", "77", "77,1", "77,2", "77,3", "77,4", "77,5", "77,6", "77,7", "77,8", "77,9", "78", "78,1", "78,2", "78,3", "78,4", "78,5", "78,6", "78,7", "78,8", "78,9", "79", "79,1", "79,2", "79,3", "79,4", "79,5", "79,6", "79,7", "79,8", "79,9", "8", "8,1", "8,2", "8,3", "8,4", "8,5", "8,6", "8,7", "8,8", "8,9", "80", "80,1", "80,2", "80,3", "80,4", "80,5", "80,6", "80,7", "80,8", "80,9", "81", "81,1", "81,2", "81,3", "81,4", "81,5", "81,6", "81,7", "81,8", "81,9", "82", "82,1", "82,2", "82,3", "82,4", "82,5", "82,6", "82,7", "82,8", "82,9", "83", "83,1", "83,2", "83,3", "83,4", "83,5", "83,6", "83,7", "83,8", "83,9", "84", "84,1", "84,2", "84,3", "84,4", "84,5", "84,6", "84,7", "84,8", "84,9", "85", "85,1", "85,2", "85,3", "85,4", "85,5", "85,6", "85,7", "85,8", "85,9", "86", "86,1", "86,2", "86,3", "86,4", "86,5", "86,6", "86,7", "86,8", "86,9", "87", "87,1", "87,2", "87,3", "87,4", "87,5", "87,6", "87,7", "87,8", "87,9", "88", "88,1", "88,2", "88,3", "88,4", "88,5", "88,6", "88,7", "88,8", "88,9", "89", "89,1", "89,2", "89,3", "89,4", "89,5", "89,6", "89,7", "89,8", "89,9", "9", "9,1", "9,2", "9,3", "9,4", "9,5", "9,6", "9,7", "9,8", "9,9", "90", "90,1", "90,2", "90,3", "90,4", "90,5", "90,6", "90,7", "90,8", "90,9", "91", "91,1", "91,2", "91,3", "91,4", "91,5", "91,6", "91,7", "91,8", "91,9", "92", "92,1", "92,2", "92,3", "92,4", "92,5", "92,6", "92,7", "92,8", "92,9", "93", "93,1", "93,2", "93,3", "93,4", "93,5", "93,6", "93,7", "93,8", "93,9", "94", "94,1", "94,2", "94,3", "94,4", "94,5", "94,6", "94,7", "94,8", "94,9", "95", "95,1", "95,2", "95,3", "95,4", "95,5", "95,6", "95,7", "95,8", "95,9", "96", "96,1", "96,2", "96,3", "96,4", "96,5", "96,6", "96,7", "96,8", "96,9", "97", "97,1", "97,2", "97,3", "97,4", "97,5", "97,6", "97,7", "97,8", "97,9", "98", "98,1", "98,2", "98,3", "98,4", "98,5", "98,6", "98,7", "98,8", "98,9", "99", "99,1", "99,2", "99,3", "99,4", "99,5", "99,6", "99,7", "99,8", "99,9"), class = "factor")), row.names = c(NA, 20L), class = "data.frame") At first, I though it was a problem with class of variables (numeric, factor...) but even when I convert to numeric it doesnt work... Data$Pmanche <- levels(Data$Pmanche)[Data$Pmanche] Data$Pcsge <- levels(Data$Pcsge)[Data$Pcsge] Thanks for your time! Here is my code: ## definition workdirectory setwd(dir="C:/Users/F596028/Documents/nouveau dossier/Optimisation") ############################## # Packages # ############################## # Graphics #install.packages("ggplot2") library(ggplot2) ############################## # ouverture du fichier Excel # ############################## ## Fichiers extension .csv du repertoir files <- list.files(pattern = "\\.csv$") files <- sort(files) ## Enregistrement des titres headers <- read.csv("Classeur1.csv", header = F, nrows = 1, as.is = T, sep=";") ## Enregistrement des données Sub1 <- read.csv(files, skip=1, header=F, sep=";") colnames(Sub1)=headers Pmanche<-Sub1[,c(3)] Pcsge<-Sub1[,c(4)] Data <- data.frame(Pmanche,Pcsge) ############################## # Plots # ############################## #Data$Pmanche <- levels(Data$Pmanche)[Data$Pmanche] #Data$Pcsge <- levels(Data$Pcsge)[Data$Pcsge] p<- ggplot(Data, aes(Pmanche,Pcsge)) p + geom_point() + scale_x_continuous(breaks=1:10)
Ok, I solved it. The problem was the data source. I learned we need to be careful when taking data from excel... Decimals must be indicated with "." and not "," Thanks
Is there a way to have separate weighted edges for ins and outs in igraph R?
I'm making a directed network in R studio with the igraph package. I would like to display two edges between nodes where applicable, both weighted, one for ins and one for outs. I'm very new to R and managed to get weighted edges that compile both ins and outs but would like them separated. I've googled my problem with no avail, it might be from phrasing it wrong. I apologize in advance if I worded it badly. EDIT: Minimal reproducible sample: OPR.df <- data.frame("From" = c(c("8", "8", "8", "8", "7", "25", "24", "1A", "12", "12"), c("12", "12", "12", "17", "17", "17"), c("17", "17", "17", "17"), c("17", "17", "17", "17", "17", "9A", "9", "17", "9", "17", "9"), c("9", "17", "17", "17")), "To" = c(c("8", "8", "8", "7", "25", "24", "1A", "12", "12", "12"), c("12", "12", "17", "17", "17", "17"), c("17", "17", "17", "17"), c("17", "17", "17", "17", "9A", "9", "17", "9", "17", "9", "17"), c("17", "17", "17", "17"))) opr.d <- graph_from_data_frame(d = OPR.df, directed = T) # I think this is the part where I set this?? E(opr.d)$weight <- 1 opr.sd <- simplify(opr.d, remove.multiple = T, remove.loops = F, edge.attr.comb = c(weight = "sum", type = "ignore")) E(opr.sd)$width <- E(opr.sd)$weight/3
There are a number of things that you can do to make the two-way links more visible. First, plotting using the default layout crowds the vertices 9, 9A and 17 too close together. There is no room to see the edges. I will use layout_with_graphopt , which works fine for this example, although for more complex examples you may need to tune up the layout even more. set.seed(4321) plot(opr.sd, xpd=NA) set.seed(4321) plot(opr.sd, layout=layout_with_graphopt) Of course, we still have the problem from your original question: the arrows overlap each other. You can fix this using the edge.curved argument. I wanted all of the arrows to be straight except where they overlap, so I created a customized curvature vector to adjust only the overlapping edges. Also, the arrow heads are too big and made it hard to see the arrows, so I made the heads a bit smaller. All together, we get: CURV = rep(0,ecount(opr.sd)) CURV[2] = 0.6 CURV[11] = 0.6 CURV[13] = 0.6 set.seed(4321) plot(opr.sd, layout=layout_with_graphopt, edge.arrow.size=0.7, edge.curved=CURV, frame=T) You might still want to tweak this a bit, but I think this shows the path to solving your problem.
applying if statement for list within list in r
I am trying to run over a list of lists. Each line has 29 lists, and each list has 6 numbers stored as strings. An example looks like the following dput(M[6000]) list(list(c("0", "1", "19", "785", "-3150", "0.90"), c("4", "2", "-1", "5550", "4400", "0.00"), c("1", "3", "6", "3319", "-2558", "1.49"), c("1", "4", "1", "4573", "-435", "1.24"), c("0", "5", "6", "1137", "-2828", "2.28"), c("0", "6", "24", "1668", "-1143", "2.76"), c("1", "7", "2", "2859", "-720", "1.40"), c("1", "8", "23", "420", "-3346", "1.57"), c("1", "9", "26", "2290", "752", "1.23"), c("1", "10", "8", "1208", "-2842", "2.14"), c("0", "11", "11", "-219", "-374", "1.26"), c("0", "12", "3", "-69", "-2403", "2.24"), c("0", "13", "1", "-3488", "-830", "0.17"), c("1", "14", "7", "2102", "-1404", "1.24"), c("1", "15", "3", "1746", "-3481", "1.59"), c("3", "16", "0", "720", "-1425", "0.47"), c("1", "17", "9", "170", "-2257", "3.14"), c("0", "18", "5", "-351", "-1564", "1.08"), c("4", "19", "-1", "5550", "4400", "0.00"), c("3", "20", "1", "3304", "-3448", "1.78"), c("1", "21", "4", "2289", "-1873", "3.13"), c("0", "22", "2", "175", "-3080", "1.28"), c("1", "23", "12", "877", "140", "1.52"), c("0", "24", "8", "871", "-1933", "4.11"), c("0", "25", "9", "3185", "-2548", "1.50"), c("4", "26", "-1", "5550", "4400", "0.00"), c("3", "27", "2", "-290", "3415", "0.56"), c("4", "28", "-1", "5550", "4400", "0.00"), c("0", "29", "32", "2176", "-2145", "1.58"))) For each line, I am trying to run over the 29 lists and save only the lists that has the 3rd element equal to 4. For one line it would be: if(as.numeric(M[[6000]][[1]][3]) == 4) M[[6000]][[1]] I have tried something down the line of MP4 <- lapply(M, function(x) if(as.numeric(x[[1]][3]) == 4) x[[1]]) without luck.
The purrr package is very good at those kinds of problems: library(purrr) M %>% map(.f = keep, .p = ~ .x[[3]] == "4") # [[1]] # [[1]][[1]] # [1] "1" "21" "4" "2289" "-1873" "3.13" Edit per your comment: Let's make another list, M_2, to illustrate the issue: M_2 <- c(M, list(list())) M_2 %>% map(.f = keep, .p = ~ .x[[3]] == "4") # [[1]] # [[1]][[1]] # [1] "1" "21" "4" "2289" "-1873" "3.13" # # # [[2]] # list() Then simply discard lists that are equal to list(): M_2 %>% map(.f = keep, .p = ~ .x[[3]] == "4") %>% discard(identical, list()) # [[1]] # [[1]][[1]] # [1] "1" "21" "4" "2289" "-1873" "3.13"
To use base R, you can use Filter: lapply(M, Filter, f = function(x){x[[3]] == '4'}) ## [[1]] ## [[1]][[1]] ## [1] "1" "21" "4" "2289" "-1873" "3.13" To filter out empty elements of a larger list, Filter twice: # using #apom's data from above Filter(function(x){length(x) != 0}, lapply(M_2, Filter, f = function(x){x[[3]] == '4'})) ## [[1]] ## [[1]][[1]] ## [1] "1" "21" "4" "2289" "-1873" "3.13"
Here is one way to loop through the list and create a new one which saves elements according to your criteria of third element equal to 4. new_dl <- list() j <- 1L for (l in 1L:length(dl)) { new_dl[[l]] <- list() for (i in 1L:length(dl[[1]])) if (dl[[l]][[i]][3] == 4) { new_dl[[l]][[j]] <- dl[[l]][[i]] j <- j + 1L } j <- 1L }
ggplot2 for procrustes rotation in vegan
I want to plot procrustes rotations between to RDA-objects obtained by vegan with ggplot2. library(vegan) #perform two RDAs, do procrustes: pro.test <- procrustes(rda.t1,rda.t2) I extracted the x,y coordinates from list of class "procrustes" and added a factor "dates". test <- data.frame(rda1=pro.test$Yrot[,1], rda2=pro.test$Yrot[,2]) test$dates <- c(rep("A", 8), rep("B",8), rep("C", 8)) test.2 <- data.frame(rda1=pro.test$X[,1], rda2=pro.test$X[,2]) test.2$dates <- c(rep("A", 8), rep("B",8), rep("C", 8)) Now the basic plot: ggplot() + geom_point(data=test, aes(x=rda1, y=rda2, color=dates)) + geom_point(data=test.2,aes(x=rda1, y=rda2, color=dates)) The part i cannot do is the plotting of small lines between each corresponding point in test and test.2 Vegan does plot these rotations with arrows rather than connected points. However, vegan does not khow to color according to sampling groups/factors, which is important for me. Having arrows in the ggplot would be extremely great - i know there is a geom_segment with the argument "arrow". Could you help me? the dput of pro.test is below. dput(pro.test) structure(list(Yrot = structure(c(0.126093537705143, 0.196350569855869, -0.0513472841582749, -0.304416713452662, 0.210682972922012, -0.0219477831881197, -0.24519038499101, 0.338357488742126, -0.399739151138497, -0.366424716631558, 0.0321561053701086, 0.565794811541598, 0.606054432756139, -0.0122819831669951, -0.00403199420346042, -0.0448308879361932, 0.0631101371381566, -0.150820933315408, -0.018216051372273, -0.68513841544701, -0.117446131920294, -0.450735018917557, 0.25749869839177, 0.47646869541639, -0.211447138648954, -0.236584149111598, -0.0316882271224907, -0.281680981927695, -0.182346139754316, -0.366221121187894, -0.263915986724565, -0.203160918536977, 0.209888424862468, 0.219400450315756, 0.143569801341895, 0.258388604988749, 0.542334722496036, 0.465147580652753, 0.294835945722885, 0.523372408452242, 0.0739580893460179, 0.242768571724456, 0.0409877673276456, -0.0942111509903291, -0.193072299067071, -0.38889179801965, -0.352882980509932, -0.208549475629433 ), .Dim = c(24L, 2L), .Dimnames = list(c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25"), NULL)), X = structure(c(0.0860177119127241, 0.217144585357183, -0.0301829830202831, -0.246142550516987, 0.230574651598493, 0.00485065775494245, -0.225907453854864, 0.371465194869491, -0.395330365511425, -0.359255005182027, -0.00775013746753128, 0.47442649486468, 0.519983070801763, -0.0146878517934982, 0.0377018407084686, -0.0885829362985767, 0.0935962405791314, -0.186192083265912, 0.00247095461296341, -0.655467761687806, -0.0966978065526177, -0.398672122636169, 0.275589258531376, 0.39104839619648, -0.273098318897548, -0.237373845171625, -0.0351119316278201, -0.279271270040404, -0.171188235636994, -0.342350443283954, -0.297148604541773, -0.21965804713297, 0.269830887309913, 0.268669489120665, 0.143826114581508, 0.229549645414776, 0.531869658831067, 0.479136042616735, 0.380638462867711, 0.548249030471031, 0.161449266776772, 0.282765937749097, 0.0756433464279055, 0.00516171212969907, -0.195519622624857, -0.568932423412245, -0.381681091857682, -0.375455760069009 ), .Dim = c(24L, 2L), const = 1.30375728392289, .Dimnames = list( c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25"), c("RDA1", "RDA2")), "`scaled:center`" = structure(c(1.3588667228485e-17, 4.69820941410385e-18), .Names = c("RDA1", "RDA2"))), ss = 0.146265769408323, rotation = structure(c(-0.958883328045618, 0.283800569407742, 0.283800569407742, 0.958883328045619), .Dim = c(2L, 2L)), translation = structure(c(-9.76742606822348e-18, 1.35523649355013e-17 ), .Dim = 1:2), scale = 0.918742698883168, xmean = structure(c(1.3586408473959e-17, 4.71176194125992e-18), .Names = c("RDA1", "RDA2")), symmetric = FALSE, call = procrustes(X = rda.t1, Y = rda.t2), svd = structure(list( d = c(2.51563498111738, 2.16729713036852), u = structure(c(0.743008138366833, 0.669282381600362, 0.669282381600362, -0.743008138366833 ), .Dim = c(2L, 2L)), v = structure(c(-0.522515395489416, 0.852629850214347, -0.852629850214347, -0.522515395489416 ), .Dim = c(2L, 2L))), .Names = c("d", "u", "v"))), .Names = c("Yrot", "X", "ss", "rotation", "translation", "scale", "xmean", "symmetric", "call", "svd"), class = "procrustes")
Does this do the job? library(ggplot2) library(grid) ctest <- data.frame(rda1=pro.test$Yrot[,1], rda2=pro.test$Yrot[,2],xrda1=pro.test$X[,1], xrda2=pro.test$X[,2],dates=rep(c("A","B","C"),each=8)) ggplot(ctest) + geom_point(aes(x=rda1, y=rda2, colour=dates)) + geom_point(aes(x=xrda1, y=xrda2, colour=dates)) + geom_segment(aes(x=rda1,y=rda2,xend=xrda1,yend=xrda2,colour=dates),arrow=arrow(length=unit(0.2,"cm")))