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
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. .. ..
Please provide more detailed information here.
-
Answer # 1
Related articles
- regarding the method to output the histograms of all columns at once
- python - about the error log output method
- python - euler method if value is not output if statement mathematics differential equation
- ruby - value value output method
- python elliptic equation csv output method not understood
- about output method in case of complicated condition of mysql
- Keras tips-get the output method of a certain network layer
- a method to output the calculation result at that time every time the for statement is executed 100 times
- c language: method that does not output 0 in loop output using array
- python - output method of csv file
- [access] output method with sql command
- about r data output
- java - about array output method
- jupyter notebook clear output method
- php - i want to add a condition within 2 hours to this method
- % is output at the end of sentence by ruby print method
- javascript - method to output the truth result of the condition to the count variable for each judgment
- i want to clean up the output method for multiple arrays in c language
- php - [wordpress] output method that specifies multiple fields of advanced custom fields
Related questions
- python : I want to make a 3D surface graph from CSV in Matplotlib
- r - how to save each split data as a csv file
- graph drawing using python pandas matplotlib
- i want to read only the first sequence when reading with readcsv
- csv load error&heatmap question in python
- how to arrange heatmaps in python
- error in readtable resolution of "'file' must be a string or a connection"
- python - i want to generate a graph network from a matrix csv file
- data cannot be read
If fill=A is set to fill=B, each B is color coded.
However, since B is a numerical value, it may be useless.
It would work if you convert B to factor like this and then set fill=B.