2016-05-13 4 views
2

Ich habe folgende Daten:Grundstück nebeneinander Boxplots für zwei Spalten aus derselben Tabelle in R

structure(list(osc = c(14944966.1544549, 21761557.221199, 22468349.3727696, 
25347942.08608, 23753968.4211987, 21988336.4211988, 24782010.0211988, 
23466022.821199, 24862768.4211988, 24753030.8211989, 6290574.27199998, 
6347336.50713587, 6133022.93504007, 6096474.45708794, 6310948.70553584, 
6730668.06553585, 7041845.44716779, 6834310.72460792, 7099525.34016, 
7427605.81836809, 6489665.40799994, 3923620.15923189, 5597911.8079998, 
5246583.80800014, 5770297.40799987, 5486879.80800004, 6084583.80800003, 
6719183.80800007, 6575468.60799991, 10992555.0079998), phone = c(14012229.0213694, 
21428112.3570197, 21387319.7062893, 23452910.4634375, 23561326.6405997, 
21295405.7333708, 24791075.2993385, 23077156.3984319, 24595401.2681341, 
24576961.6364291, 6436497.31657422, 6273285.60788477, 5998908.36035547, 
5837113.11736719, 6138679.45996679, 6229959.76306446, 6790623.7462578, 
6752280.48147853, 6625959.55551369, 6979249.86094727, 6642155.1844375, 
3965572.43175781, 5462667.62250977, 5232575.67903125, 5466322.91543554, 
5380533.88633204, 5814654.14943164, 6482157.46073438, 6269535.74795312, 
10938578.8058379), type = c("local", "local", "local", "local", 
"local", "local", "local", "local", "local", "local", "up", "up", 
"up", "up", "up", "up", "up", "up", "up", "up", "down", "down", 
"down", "down", "down", "down", "down", "down", "down", "down" 
)), .Names = c("osc", "phone", "type"), row.names = c(NA, 30L 
), class = "data.frame") 

Wie kann ich ein Grundstück erhalten, die insgesamt 6 Boxplots umfassen wird, wo die Daten sein gruppiert zuerst nach Typ und dann für jeden Typ gibt es ein Boxplot für die osc Spalte und ein Boxplot für die phone Spalte?

Antwort

4

hier ist eine Option reshape mit:

library(reshape2) 
df2 <- melt(df, id.vars="type") 
op <- par(ps=12, mar=c(5,4,1,1)) 
boxplot(value ~ variable + type, df2, las=2, col=c(5:6)) 
par(op) 

enter image description here

0

Suchen Sie etwas wie das?

par(mfcol=c(1,2)) 
boxplot(phone ~ type, data=d, main="phone") 
boxplot(osc ~ type, data=d, main="osc") 
3
require(ggplot2) 
require(tidyr) 
td<-tidyr::gather(d,key=type) 
names(td)<-c("type","osc_local","value") 
ggplot(data=td,aes(y=value,x=type,fill=osc_local))+geom_boxplot() 

hoffe, das hilft! ![enter image description here] 1

+0

hilft definitiv, nur, dass ich war auf der Suche nach einer reinen R-Lösung, die ist, warum ich – cross

+1

sicher die andere Antwort akzeptiert! Ich bin ein Fan von ggplot, aber es war gut zu lernen, wie es ohne das Paket geht! –

0
par(mfrow = c(1,2)) 
boxplot(dataframe$osc ~ dataframe$type , main = "phone") 
boxplot(dataframe$phone ~ dataframe$type , main = "osc") 
Verwandte Themen