r - Make step function adopt 90 degree transitions -


i suspect may extremely stupid question, here goes! (also, apologies if better suited crossvalidated, i'm not sure @ point whether programming issue, or needs approaching more statistically...

i have created step-function cumseg (a.k.a staircase function, a.k.a peicewise constant function) , fit discontinuous (x axis) data, in code/figure below.

that's fine, i'm pretty happy it, i'm wondering if can make step function (red line) have vertical transition (i.e both 'shoulders' of function 90 degrees). in order value on x-axis have between current 2 jump points. possible?

if so, brings me question, how might 1 represent st. deviation on line on chart if has these 90 degree transitions , vertical descent?

# plotting step-functions on gc-operon data.  require(ggplot2) library("ggplot2") require(reshape2) library("reshape2") require(scales) library(rcolorbrewer) library(cumseg)  df <- structure(list(pvc1 = 0.4019026, pvc2 = 0.4479259, pvc3 = 0.4494118, pvc4 = 0.4729437,                  pvc5 = 0.4800556, pvc6 = 0.449229, pvc7 = 0.4905295, pvc8 = 0.4457566,                  pvc9 = 0.4271259, pvc10 = 0.4850341, pvc11 = 0.4369965, pvc12 = 0.4064052,                  pvc13 = 0.3743776, pvc14 = 0.3603853, pvc15 = 0.3965469, pvc16 = 0.365461),                 .names = c("pvc1","pvc2","pvc3","pvc4","pvc5","pvc6","pvc7","pvc8",                            "pvc9","pvc10","pvc11","pvc12","pvc13","pvc14","pvc15","pvc16"),                 class = "data.frame",                 row.names = c(na, -1l)             )  melted_df <- melt(df, variable.name = "locus", value.name = "gc") st_dev <- c(0.023031363,    0.024919217,    0.017371129,         0.019008759,    0.026650605,    0.026904926,         0.024227542,    0.017767553,    0.026152478,         0.039770898,    0.023929714,    0.028845442,         0.015572219,    0.024967336,    0.014955416,    0.024569096)  operon_gc <- 0.408891366 opgc_stdev <- 0.015712091 genome_gc <- 0.425031611 gengc_stdev <- 0.007587437  stepfunc <- jumpoints(y=melted_df$gc*100, k=1, output="1")  gc_chart <- ggplot(melted_df, aes(locus, gc*100, fill=locus,)) +                 geom_bar(width=0.6, stat = "identity") gc_chart <- gc_chart + ylab("gc content (%)") gc_chart <- gc_chart + theme(axis.text.x = element_text(angle=45, hjust=1)) gc_chart <- gc_chart + geom_abline(intercept=operon_gc*100,                                slope=0,                                colour="gray",                                linetype=3,                                show.legend =true) gc_chart <- gc_chart + geom_text(aes(15.7, 41.7, label="operon gc"),                              size=5,                              color="gray") gc_chart <- gc_chart + geom_abline(intercept=genome_gc*100,                                slope=0,                                colour="black",                                linetype=3,                                show.legend = true)  gc_chart <- gc_chart + geom_text(aes(15.7, 43.3, label="genome gc"),                              size=5,                              color="black")  gc_chart <- gc_chart + coord_cartesian(ylim=c(30,55))  gc_chart <- gc_chart + geom_errorbar(width=.2, size=0.4, color="azure4", aes(locus,                  ymin = (gc - cbind(melted_df, st_dev)$st_dev)*100,                  ymax = (gc + cbind(melted_df, st_dev)$st_dev)*100)) gc_chart <- gc_chart + geom_line(linetype=2,aes(x=as.numeric(locus), y=stepfunc$fitted.values, colour="red", group=1))  gc_chart 

enter image description here

edit: @gregor, geom_step has achieved desired effect thank (literally substituting line step in code generates this: enter image description here

however, graph, breakpoint @ pvc12. yet, when extracting breakpoint value function...

> stepfunc$psi  v  11  

in case graph becomes misleading , perhaps i'm better off previous version demonstrates there break 'between 11 , 12'.

ggplot great @ plotting data give it. x values 1:12, , y values 45's 37's. if don't having y values (and changes in y values) defined @ integer values of x, change values!

step_df = data.frame(x = c(1, 11.5, 16), y = c(45.24568, 37.5, 37.5))  gc_chart + geom_step(data = stepdf, linetype=2,                      aes(x = x, y = y, colour="red", group=1),                      inherit.aes = f) 

i'll leave programmatically defining appropriate step_df you.


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -