Ero sivun ”OpasnetUtils/Ograph” versioiden välillä

Opasnet Suomista
Siirry navigaatioon Siirry hakuun
Rivi 9: Rivi 9:


<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 = character(),  
type = character(),  
fill = NA,  
fill = NA,  
...
...
) {
) {
if(length(ovariable@output == 0)) ovariable <- EvalOutput(ovariable)
if(class(ovariable) == "ovariable")  {
if(nrow(ovariable@output) == 0) ovariable <- EvalOutput(ovariable)
data <- ovariable@output
title <- ovariable@name
if(length(y) == 0) y <- paste(title, "Result", sep = "")
} else {
data <- ovariable
title <- character()
if(length(y) == 0) y <- "Result"
}
if(length(type) == 0) {
if(length(type) == 0) {
if("Iter" %in% colnames(ovariable@output)) type <- geom_boxplot() else type <- geom_bar()
if("Iter" %in% colnames(data)) type <- geom_boxplot() else type <- geom_bar(stat = "identity")
}
}
out <- ggplot(ovariable@output, aes_string(x = x, y = y, fill = fill)) + # Määritellään kuvan sarakkeet
out <- ggplot(data, aes_string(x = x, y = y, fill = fill)) + # Määritellään kuvan sarakkeet
type +  
type +  
theme_grey(base_size=24) + # Fontin kokoa suurennetaan
theme_grey(base_size=24) + # Fontin kokoa suurennetaan
labs(
labs(
title = ovariable@name,
title = title,
y = paste(unique(ovariable@output[[paste(ovariable@name, "Yksikkö", sep = "")]]), sep = "", collapse = ", ")
y = paste(unique(data[[paste(title, "Yksikkö", sep = "")]]), sep = "", collapse = ", ")
) +
) +
theme(axis.text.x = element_text(angle = 90, hjust = 1)) # X-akselin tekstit käännetään niin että mahtuvat
theme(axis.text.x = element_text(angle = 90, hjust = 1)) # X-akselin tekstit käännetään niin että mahtuvat
return(out)
return(out)
}
}
</rcode>
</rcode>

Versio 30. maaliskuuta 2013 kello 04.49




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

+ Näytä koodi