Как упомянуто в заголовке, как мне построить data.tree с соответствующими значениями?
Заранее спасибо за помощь. Уже в моем уме: (
Редактировать: Больше информации:
Данные, которые я пытаюсь визуализировать, представляют собой опрос, в котором респонденту задают основной вопрос, в котором, если он или она ответили «да», и к первому ответят дополнительные вопросы. Я пытаюсь визуализировать процент респондентов, которые ответили «да» или «нет» на каждый вопрос, для которого моя идея состоит в том, чтобы использовать для этого дерево решений, подобное графику.
library(data.tree)
library(networkD3)
# create simple tree
tree <- Node$new("Primary Node")
tree1 <- tree$AddChild("Tree1")
tree2 <- tree$AddChild("Tree2")
tree3 <- tree1$AddChild("Tree3")
tree4 <- tree2$AddChild("Tree4")
# assign value
tree1$value <- 1
tree2$value <- 2
tree3$value <- 3
tree4$value <- 4
# plot tree ## No values reflected
plot(tree)
simpleNetwork(ToDataFrameNetwork(tree))
Edit:
Пробовал ваше решение, Gilean, работает довольно хорошо, однако, как заставить дочерний узел распознавать одни и те же слова в разных деревьях? И как настроить слова по размеру шрифта или выравнивание, чтобы оно не мешало визуализации?
library(igraph)
# requires the changing of No to No1, No2 and so forth to prevent it merging into one large node
df <- data.frame(parent = c("Have you ever had your cholesterol fat levels in your blood measured by a doctor or other health worker",
"Have you ever had your cholesterol fat levels in your blood measured by a doctor or other health worker",
"Have you ever been told by a doctor or other health worker that you have raised cholesterol",
"Have you ever been told by a doctor or other health worker that you have raised cholesterol",
"Were you first told in the past 12 months",
"Were you first told in the past 12 months",
"In the past two weeks have you taken any oral treatment medication for raised total cholesterol prescribed by a doctor or other health worker",
"In the past two weeks have you taken any oral treatment medication for raised total cholesterol prescribed by a doctor or other health worker",
"Have you ever seen a traditional healer for raised cholesterol",
"Have you ever seen a traditional healer for raised cholesterol",
"Are you currently taking any herbal or traditional remedy for your raised cholesterol",
"Are you currently taking any herbal or traditional remedy for your raised cholesterol"),
child = c("No", "Have you ever been told by a doctor or other health worker that you have raised cholesterol",
"No1", "Were you first told in the past 12 months",
"No2", "In the past two weeks have you taken any oral treatment medication for raised total cholesterol prescribed by a doctor or other health worker",
"No3", "Have you ever seen a traditional healer for raised cholesterol",
"No4", "Are you currently taking any herbal or traditional remedy for your raised cholesterol",
"No5", "Yes"),
value = 1:12)
tree <- graph_from_data_frame(df, directed = TRUE)
plot(tree, vertex.label = V(tree)$name, edge.label = E(tree)$value, layout=layout_as_tree, vertex.size = c(10, E(tree)$value))