2011-08-09 9 views

Odpowiedz

14

Korzystanie ggplot byś go o to w następujący sposób:

Skonfiguruj dane. Nic dziwnego tutaj, ale wyraźnie wartości poniżej osi będą ujemne.

dat <- data.frame(
    group = rep(c("Above", "Below"), each=10), 
    x = rep(1:10, 2), 
    y = c(runif(10, 0, 1), runif(10, -1, 0)) 
) 

Działka przy użyciu ggplot i geom_bar. Aby zapobiec podsumowaniu danych przez geom_bar, podaj stat="identity". Podobnie, układanie w stosy należy wyłączyć, podając position="identity".

library(ggplot2) 
ggplot(dat, aes(x=x, y=y, fill=group)) + 
    geom_bar(stat="identity", position="identity") 

enter image description here

0

Odbywa się to z ggplot2. Najpierw podaj dane i umieść oba razem w stopie.

library(ggplot2) 

dtfrm <- data.frame(x = 1:10, y1 = rnorm(10, 50, 10), y2 = -rnorm(10, 50, 10)) 
dtfrm.molten <- melt(dtfrm, id = "x") 

Następnie należy wykres

ggplot(dtfrm.molten, aes(x , value, fill = variable)) + 
    geom_bar(stat = "identity", position = "identity") 

Perhpas inna osoba może stanowić przykład z podstawą i/lub kraty.

HTH

9

Niektóre bardzo minimalne przykłady grafik bazowych i lattice użyciu @ przykład danych Andrie za:

dat <- data.frame(
    group = rep(c("Above", "Below"), each=10), 
    x = rep(1:10, 2), 
    y = c(runif(10, 0, 1), runif(10, -1, 0)) 
) 

W grafice Base:

plot(c(0,12),range(dat$y),type = "n") 
barplot(height = dat$y[dat$group == 'Above'],add = TRUE,axes = FALSE) 
barplot(height = dat$y[dat$group == 'Below'],add = TRUE,axes = FALSE) 

bar_base

aw lattice:

barchart(y~x,data = dat, origin = 0, horizontal = FALSE) 

enter image description here

Powiązane problemy