Question

I am plotting the local clustering (transitivity with type = c('local') argument) of some graphs in a boxplot.

plot

I calculated the global transitivity of these graphs and I want to represent it as an additional line of the plot as wide as each box.

 df <- data.frame(values = c(full_trans, clus_trans), vars = rep(c("Full","Clustering"), times=c(20,20)))
 par(mfrow=c(1,1))
 boxplot(values~vars, data=df, ylim=c(0:1), yaxt='n', boxwex=0.5)

I tried abline, but it draws a line through all the plot which doesn't look how I wanted.

Was it helpful?

Solution

Create data:

d = data.frame(a=rnorm(10),b=rnorm(10))

Plot boxplots of a defined width:

my_width = 0.5
boxplot(d, boxwex=my_width)

Add lines for global transmissivity using another boxplot (green)

global_tr = 0.3
extra_d = data.frame(a=global_tr,b=global_tr)
boxplot(x = extra_d, at = c(1,2), add=T,col=3,  boxwex=my_width, border=3)

... or using segments (red)

x = 1:2
segments(x0=x-0.5*my_width, x1=x+0.5*my_width,y0=0.3, y1=0.3, col=2)

boxplot with extra line

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top