Difference between revisions of "OpasnetUtils/Ograph"

From Testiwiki
Jump to: navigation, search
 
(Vastaus: tuoreempi versio Op_fistä)
Line 10: Line 10:
  
 
<rcode name="answer">
 
<rcode name="answer">
 +
 
ograph <- function( # Määritellään yleisfunktio peruskuvaajan piirtämiseen.
 
ograph <- function( # Määritellään yleisfunktio peruskuvaajan piirtämiseen.
 
ovariable,  
 
ovariable,  
 
x,  
 
x,  
y = paste(ovariable@name, "Result", sep = ""),  
+
y = character(),  
type = geom_boxplot(),  
+
type = character(),  
fill = NA, ...
+
other = character(),
 +
fill = NA,  
 +
...
 
) {
 
) {
ovariable <- EvalOutput(ovariable)
+
if(class(ovariable) == "ovariable")  {
out <- ggplot(ovariable@output, aes_string(x = x, y = y, fill = fill)) + # Määritellään kuvan sarakkeet
+
if(nrow(ovariable@output) == 0) ovariable <- EvalOutput(ovariable)
type +  
+
data <- ovariable@output
theme_grey(base_size=24) + # Fontin kokoa suurennetaan
+
title <- ovariable@name
labs(
+
if(length(y) == 0) y <- paste(title, "Result", sep = "")
title = ovariable@name,
+
} else {
y = paste(unique(ovariable@output[[paste(ovariable@name, "Yksikkö", sep = "")]]), sep = "", collapse = ", ")
+
data <- ovariable
) +
+
title <- character()
theme(axis.text.x = element_text(angle = 90, hjust = 1)) # X-akselin tekstit käännetään niin että mahtuvat
+
if(length(y) == 0) y <- "Result"
 +
}
 +
if(length(type) == 0) {
 +
if("Iter" %in% colnames(data)) type <- geom_boxplot() else type <- geom_bar(stat = "identity")
 +
}
 +
out <- ggplot(data, aes_string(x = x, y = y, fill = fill)) # Määritellään kuvan sarakkeet
 +
out <- out + type
 +
out <- out + theme_grey(base_size=24) # Fontin kokoa suurennetaan
 +
out <- out + labs(
 +
title = title,
 +
y = paste(unique(data[[paste(title, "Yksikkö", sep = "")]]), sep = "", collapse = ", ")
 +
)
 +
out <- out + theme(axis.text.x = element_text(angle = 90, hjust = 1)) # X-akselin tekstit käännetään niin että mahtuvat
 +
if(length(other) != 0) out <- out + other
 
return(out)
 
return(out)
 
}
 
}
 +
 
</rcode>
 
</rcode>

Revision as of 04:25, 9 April 2013



Kysymys

Millainen on koodi peruskuvaajan piirtämiseen Opasnetissa? Sen on tarkoitus tuottaa yleisesti käytettyjä muuttujien kuvaajia mahdollisimman yksinkertaisella parametrisoinnilla. Mitään erityisiä kommervenkkeja ei tarvita.

Vastaus

+ Show code