Difference between revisions of "OpasnetUtils/Drafts"

From Testiwiki
Jump to: navigation, search
m
(Answer: oggplot updated)
Line 21: Line 21:
 
#################### Perus-ggplot ovariableille
 
#################### Perus-ggplot ovariableille
  
oggplot <- function(
+
oggplot <- function (
ova, #ovariable to be plotted
+
ova, # ovariable to be plotted
x, # index for x axis
+
x, # Index for x axis
weight = NULL, # weights to be used (ovariable result by default)
+
weight = NULL, # Index for y axis (default: result column)
fill = NULL, # index for stack colour
+
fill = NULL, # Index for colour code
labs.title = NULL, # graph main title
+
base_size = BS, # Base size for graph font (object BS must exist!)
labs.x = NULL, # x axis label
+
turnx = FALSE, # Turn x axis labels vertically?
labs.y = NULL, # y axis label
+
binwidth = NULL # Width of bins
base_size = BS, # base_size for font
+
)
turnx = FALSE
+
{
) {
+
if (is.null(weight))  
 
+
weight <- paste(ova@name, "Result", sep = "")
if(is.null(weight)) weight <- paste(ova@name, "Result", sep = "")
+
plo <- ggplot(ova@output, aes_string(x = x, fill = fill, weight = weight)) +
plo <- ggplot(ova@output) +  
+
theme_gray(base_size = base_size) 
geom_bar(
+
if(any(ova@output[[weight]] > 0)) {
data = subset(ova@output, ova@output[[rescol]] > 0),
+
plo <- plo + geom_bar(
aes_string(x = x, weight = weight, fill = fill),
+
data = subset(ova@output, ova@output[[weight]] > 0),
position="stack"
+
position = "stack",
) +
+
binwidth = binwidth
geom_bar(
 
data = subset(ova@output, ova@output[[rescol]] < 0),
 
aes_string(x = x, weight = weight, fill = fill),
 
position="stack"
 
) +
 
theme_gray(base_size = base_size) +
 
labs(
 
title = labs.title,
 
y = labs.y,
 
x = labs.x
 
 
)
 
)
if(any(ova@output[[rescol]] < 0)) plo <- plo + geom_hline(aes(yintercept=0))
+
}
if(turnx) plo <- plo + theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5)) # Turn text and adjust to right
+
if(any(ova@output[[weight]] < 0)) {
 +
plo <- plo + geom_bar(
 +
data = subset(ova@output, ova@output[[weight]] < 0),
 +
position = "stack",
 +
binwidth = binwidth
 +
) + geom_hline(aes(yintercept = 0))
 +
}
  
 +
if (turnx)
 +
plo <- plo + theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5))
 
return(plo)
 
return(plo)
 
}
 
}

Revision as of 13:05, 4 September 2015



Question

Which functions are so useful that they should be taken into OpasnetUtils package? This page contains draft function which will be included when they are good enough and found important.

Answer

Call the objects stored by this code from another rode with this command:

objects.latest("Op_en6007", code_name = "answer")

+ Show code

See also

References


Related files

<mfanonymousfilelist></mfanonymousfilelist>