ggraph(m,layout=coords$layout)+geom_edge_link0(width=0.2,colour="grey")+geom_node_point(col="white",size=6)+scale_x_reverse()+geom_node_text(aes(label=name))+# draw rectangle that covers input layer at x=1, min y is min of coords$y and max y is max of coords$yannotate("rect",xmin=0,xmax=.1,ymin=min(coords$layout[,2]),ymax=max(coords$layout[,2]),fill="grey",alpha=0.7)
# Load the required librarieslibrary(ggplot2)library(ggpp)library(tidyverse)library(patchwork)# Create the Gaussian curve plots for each input nodeinput_node_1<-ggplot(data.frame(x =seq(-3, 3, length.out =100)), aes(x))+stat_function(fun =dnorm, args =list(mean =1, sd =.4))+theme_void()+theme(plot.margin =margin(0, 0, 0, 0))input_node_2<-ggplot(data.frame(x =seq(-3, 3, length.out =100)), aes(x))+stat_function(fun =dnorm, args =list(mean =2, sd =.4))+theme_void()+theme(plot.margin =margin(0, 0, 0, 0))input_node_3<-ggplot(data.frame(x =seq(-3, 3, length.out =100)), aes(x))+stat_function(fun =dnorm, args =list(mean =3, sd =.4))+theme_void()+theme(plot.margin =margin(0, 0, 0, 0))# Create the main plotmain_plot<-ggplot()+theme_void()+theme(plot.margin =margin(0, 0, 0, 0))+annotate("plot_npc", npcx =0.2, npcy =0.8, label =input_node_1)+annotate("plot_npc", npcx =0.5, npcy =0.8, label =input_node_2)+annotate("plot_npc", npcx =0.8, npcy =0.8, label =input_node_3)+annotate("text", x =0.2, y =0.7, label ="Input Node 1")+annotate("text", x =0.5, y =0.7, label ="Input Node 2")+annotate("text", x =0.8, y =0.7, label ="Input Node 3")+annotate("text", x =0.5, y =0.6, label ="Input Layer", fontface ="bold")+annotate("text", x =0.5, y =0.3, label ="Output Layer", fontface ="bold")+annotate("text", x =0.5, y =0.1, label ="ALM + EXAM Response", fontface ="bold")# Print the main plotprint(main_plot)# Create the Gaussian curve plots for each input nodeinput_node_1<-ggplot(data.frame(x =seq(-3, 3, length.out =100)), aes(x))+stat_function(fun =dnorm, args =list(mean =0, sd =1))+theme_void()+theme(plot.margin =margin(0, 0, 0, 0))input_node_2<-ggplot(data.frame(x =seq(-3, 3, length.out =100)), aes(x))+stat_function(fun =dnorm, args =list(mean =2.2, sd =1))+theme_void()+theme(plot.margin =margin(0, 0, 0, 0))input_node_3<-ggplot(data.frame(x =seq(-3, 3, length.out =100)), aes(x))+stat_function(fun =dnorm, args =list(mean =4.3, sd =.1))+theme_void()+theme(plot.margin =margin(0, 0, 0, 0))# Create the main plotmain_plot<-ggplot()+theme_void()+theme(plot.margin =margin(0, 0, 0, 0))+annotate("plot_npc", npcx =0.2, npcy =0.8, label =input_node_1, width =0.1, height =0.1)+annotate("plot_npc", npcx =0.5, npcy =0.8, label =input_node_2, width =0.1, height =0.1)+annotate("plot_npc", npcx =0.8, npcy =0.8, label =input_node_3, width =0.1, height =0.1)+annotate("text", x =0.2, y =0.9, label ="Input Node 1")+annotate("text", x =0.5, y =0.9, label ="Input Node 2")+annotate("text", x =0.8, y =0.9, label ="Input Node 3")+annotate("text", x =0.5, y =0.6, label ="Input Layer", fontface ="bold")+annotate("rect", xmin =0.1, xmax =0.3, ymin =0.4, ymax =0.5, fill ="grey80")+annotate("rect", xmin =0.4, xmax =0.6, ymin =0.4, ymax =0.5, fill ="grey80")+annotate("rect", xmin =0.7, xmax =0.9, ymin =0.4, ymax =0.5, fill ="grey80")+annotate("text", x =0.5, y =0.3, label ="Output Layer", fontface ="bold")+annotate("text", x =0.5, y =0.1, label ="ALM + EXAM Response", fontface ="bold")print(main_plot)# Create the Gaussian curve plots for each input nodeinput_node_1<-ggplot(data.frame(x =seq(-3, 3, length.out =100)), aes(x))+stat_function(fun =dnorm, args =list(mean =0, sd =.41))+theme_void()+theme(plot.margin =margin(0, 0, 0, 0))+ggtitle("Input Node 1")input_node_2<-ggplot(data.frame(x =seq(-3, 3, length.out =100)), aes(x))+stat_function(fun =dnorm, args =list(mean =2, sd =.41))+theme_void()+theme(plot.margin =margin(0, 0, 0, 0))+ggtitle("Input Node 2")input_node_3<-ggplot(data.frame(x =seq(-3, 3, length.out =100)), aes(x))+stat_function(fun =dnorm, args =list(mean =3, sd =.41))+theme_void()+theme(plot.margin =margin(0, 0, 0, 0))+ggtitle("Input Node 3")# Create the output nodesoutput_node_1<-ggplot()+theme_void()+theme(plot.margin =margin(0, 0, 0, 0))+annotate("rect", xmin =-1, xmax =1, ymin =-1, ymax =1, fill ="blue")+ggtitle("Output Node 1")output_node_2<-ggplot()+theme_void()+theme(plot.margin =margin(0, 0, 0, 0))+annotate("rect", xmin =-1, xmax =1, ymin =-1, ymax =1, fill ="blue")+ggtitle("Output Node 2")# Combine the input and output nodes using patchworkinput_layer<-input_node_1+input_node_2+input_node_3output_layer<-output_node_1+output_node_2# Create the connection matrixconnection_matrix<-ggplot()+theme_void()+theme(plot.margin =margin(0, 0, 0, 0))+annotate("segment", x =0.2, xend =0.8, y =0.8, yend =0.2, arrow =arrow())+annotate("segment", x =0.5, xend =0.8, y =0.8, yend =0.2, arrow =arrow())+annotate("segment", x =0.8, xend =0.8, y =0.8, yend =0.2, arrow =arrow())# Combine the input layer, connection matrix, and output layermain_plot<-input_layer/connection_matrix/output_layer# Print the main plotprint(main_plot)# Function to create an input nodecreate_input_node<-function(mean, position){ggplot(data.frame(x =seq(-3, 3, length.out =100)), aes(x))+stat_function(fun =dnorm, args =list(mean =mean, sd =.3))+theme_void()+theme(plot.margin =margin(0, 0, 0, 0))+coord_cartesian(xlim =c(0, 3), ylim =c(0, 0.5))+coord_flip()+labs(title =paste("Input Node", position))+theme(plot.title =element_text(hjust =0.5))}# Function to create an output nodecreate_output_node<-function(position){ggplot()+theme_void()+theme(plot.margin =margin(0, 0, 0, 0))+annotate("rect", xmin =-1, xmax =1, ymin =-1, ymax =1, fill ="grey80")+labs(title =paste("Output Node", position))+theme(plot.title =element_text(hjust =0.5))}create_input_layer<-function(n){input_plots<-map(1:n, ~create_gaussian_plot(.x))input_layer<-wrap_plots(input_plots, ncol =1)+coord_flip()return(input_layer)}# Create the input nodesinput_nodes<-map(1:3, ~create_input_node(.x, .x))# Create the output nodesoutput_nodes<-map(1:4, ~create_output_node(.x))## Create the connection matrixconnection_matrix<-ggplot()+theme_void()+theme(plot.margin =margin(0, 0, 0, 0))+annotate("segment", x =1, xend =2, y =rep(1:3, each =4), yend =rep(1:4, times =3), arrow =arrow())# Combine the plotsinput_layer<-wrap_plots(input_nodes,byrow=FALSE,ncol=1)output_layer<-wrap_plots(output_nodes, ncol =1)main_plot<-input_layer+connection_matrix+output_layer+plot_layout(ncol =3)# Print the main plotprint(main_plot)combined_plot<-input_layer+connection_matrix+output_layer+plot_layout(ncol =3)print(combined_plot)print(input_layer)
Code
# Load the required librarieslibrary(ggplot2)library(ggpp)library(patchwork)library(tidyverse)# Function to create the input layercreate_input_layer<-function(n_nodes, stimulus=0, gamma=5){# Create a data frame with the x values and node meansdf<-expand.grid(x =seq(-3, 3, length.out =100), mean =seq(-2, 1.5, length.out =n_nodes))%>%mutate(noisyMean=map(mean,~dnorm(.x,mean,sd=.5)))df<-df%>%mutate(distance =abs(x-stimulus), noise =rnorm(n(), sd =0.05), max_activation =exp(-gamma*distance^2)+noise, y =max_activation*exp(-gamma*(x-mean)^2))# Create the plotggplot(df, aes(x, y, group =mean))+geom_line()+geom_smooth()+coord_cartesian(xlim =c(-2, 2), ylim =c(0, 1))+labs(title ="Input Layer")+theme(plot.title =element_text(hjust =0.5))}# Function to create an output nodecreate_output_node<-function(position){ggplot()+theme_void()+theme(plot.margin =margin(0, 0, 0, 0))+annotate("rect", xmin =-1, xmax =1, ymin =-1, ymax =1, fill ="grey80")+labs(title =paste("Output Node", position))+theme(plot.title =element_text(hjust =0.5))}# Create the input layerinput_layer<-create_input_layer(3)# Create the output nodesoutput_nodes<-map(1:4, ~create_output_node(.x))# Create the connection matrixconnection_matrix<-ggplot()+theme_void()+theme(plot.margin =margin(0, 0, 0, 0))+annotate("segment", x =1, xend =2, y =1:3, yend =rep(1:4, each =3), arrow =arrow())# Combine the plotsoutput_layer<-wrap_plots(output_nodes, ncol =1)main_plot<-input_layer+connection_matrix+output_layer+plot_layout(ncol =3)# Print the main plotprint(main_plot)
# Load the required packageslibrary(ggplot2)library(png)# Define the Gaussian functiongaussian<-function(x, mean, sd){1/(sd*sqrt(2*pi))*exp(-1/2*((x-mean)/sd)^2)}# Define the central values for the input nodescentral_values<-c(1, 2, 3)# Define the input stimulus valueinput_stimulus<-2# Generate a Gaussian curve image for each input nodefor(iinseq_along(central_values)){# Define the mean and standard deviation for the Gaussian curvemean<-central_values[i]sd<-1# Generate the x valuesx<-seq(mean-3*sd, mean+3*sd, length.out =100)# Generate the y valuesy<-gaussian(x, mean, sd)# Create the plotp<-ggplot(data.frame(x, y), aes(x, y))+geom_line()+theme_minimal()+labs(x ="X", y ="Activation", title =paste("Input Node", i))# Save the plot as a PNG imageggsave(paste0("gaussian_curve_input_node_", i, ".png"), plot =p, width =4, height =3)}
Code
grViz("digraph causal { # Nodes node [imagescale=true,shape = reactangle, fontname = Arial, style = filled] iv [label = 'TRT', fillcolor = '#7FC97F'] me [label = 'Mediator', shape = ellipse] dv [label = 'DLQI', fillcolor = '#7FC97F'] # Edges edge [color = black, arrowhead = normal] rankdir = LR iv -> me iv -> dv [label = 'DIRECT', fontcolor = '#7FC97F', color = '#7FC97F'] me -> dv # Graph graph [overlap = true, fontsize = 10] }")grViz("digraph causal { # Nodes node [shape = reactangle, fontname = Arial, style = filled] iv [image='gaussian_curve_input_node_1.png',label = '', fillcolor = '#7FC97F'] me [label = 'Mediator', shape = ellipse] dv [label = 'DLQI', fillcolor = '#7FC97F'] # Edges edge [color = black, arrowhead = normal] rankdir = LR iv -> me iv -> dv [label = 'DIRECT', fontcolor = '#7FC97F', color = '#7FC97F'] me -> dv # Graph graph [overlap = true, fontsize = 10] }")