Difference between revisions of "OpasnetUtils/Ograph"

From Testiwiki
Jump to: navigation, search
 
(depreciated)
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
[[op_fi:OpasnetUtils/Ograph]]
 
[[op_fi:OpasnetUtils/Ograph]]
 
[[Category:OpasnetUtils]]
 
[[Category:OpasnetUtils]]
 +
[[Category:Code under inspection]]
 
{{method}}
 
{{method}}
 +
:'''This code is depreciated. Instead, use
 +
objects.latest("Op_en6007", code_name = "answer") # [[OpasnetUtils/Drafts]]
 +
in your code to fetch official draft objects.
  
 
==Kysymys==
 
==Kysymys==
Line 10: Line 14:
  
 
<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>

Latest revision as of 14:38, 14 November 2013


This code is depreciated. Instead, use
objects.latest("Op_en6007", code_name = "answer") # OpasnetUtils/Drafts

in your code to fetch official draft objects.

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