Home>
With reference to the code in the "regression tree" in the middle of the above URL site, we have rewritten the code with the objective variable "henni" and the explanatory variables A to I as nine variables.
In the site, a box and whisker graph is finally output for each "Type", but if I rewrite it, it will be blue when B is 4, and all others will be gray, so it can not be color-coded like the site. It was

I would appreciate it if you could understand and give me some advice.

I am importing with csv, but when I output a part of the contents, it looks like the following.

head(df)
henni A B C D E F G H I
1 0.5 1 2 2 1 3 2 2 1 1
2 2.2 1 2 2 1 3 2 2 1 1
3 1.0 1 2 2 1 3 2 2 1 1
4 1.9 1 2 2 1 3 2 2 1 1
5 2.0 1 2 2 1 3 2 2 1 1
6 1.2 1 2 2 1 3 2 2 1 1

AI takes 1,2,3,4 variables.

The output result in the source code below is attached.
Six box-whisker graphs are output, but when B is 1,2,3, they all become gray.
Applicable source code
library(rpart)
library(partykit)
library(ggplot2)
library(ggparty)
df<- read.csv("test2.csv",header=T)
head(df)
rt<- rpart(henni ~ A + B + C + D + E + F + G + H + I, data = df)
#henni is the target variable A+-what to specify as an explanatory variable)
prt<- as.party(rt)
g<- ggparty(prt, terminal_space = 0.5)
g<- g + geom_edge(size = 1.5)
g<- g + geom_edge_label(colour = "grey", size = 3)
g<- g + geom_node_plot(
+ gglist = list(geom_boxplot(aes(x="",y=henni,fill = A)), theme_bw(base_size =12)),
+ scales = "fixed",
+ id = "terminal",
+ shared_axis_labels = TRUE,
+ shared_legend = TRUE,
+ legend_separator = TRUE,
+)
g<- g + geom_node_label(
+ aes(col = splitvar),
+ line_list = list(aes(label = paste("Node", id)),
+ aes(label = splitvar)),
+ line_gpar = list(list(
+ size = 10,
+ col = "black",
+ fontface = "bold"
+ ),
+ list(size = 12)),
+ ids = "inner"
+)
g<- g + geom_node_label(
+ aes(label = paste0("Node ", id, ", N = ", nodesize)),
+ fontface = "bold",
+ ids = "terminal",
+ size = 3,
+ nudge_y = 0.01
+)
g<- g + theme(legend.position = "none")
plot(g)
What I tried

https://qiita.com/besuboiu/items/bddd41cb8bd7dd9ef717
The above site has different colors for each "condition".
+ gglist = list(geom_boxplot(aes(x="",y=henni,colore = X ,fill = A)),theme_bw(base_size =12)),
I fixed it, but the result did not change. .. ..

Supplemental information (FW/tool ​​version, etc.)

Please provide more detailed information here.