Pergunta

How can I fix the following code

alpha <- 1
draws <- 15
dimen <- 10
require(MCMCpack)
x <- rdirichlet(draws, rep(alpha, dimen))
require(ggplot2)
dat <- data.frame(item=factor(rep(1:10,15)), 
             draw=factor(rep(1:15,each=10)), 
             value=as.vector(t(x)))
ggplot(dat,aes(x=item,y=value,ymin=0,ymax=value)) +
       geom_point(colour=I("blue"))       + 
       geom_linerange(colour=I("blue"))   + 
       facet_wrap(~draw,ncol=5)           + 
       scale_y_continuous(lim=c(0,1))     +
       opts(panel.border=theme_rect())

to not to get this empty plot:

empty Dirichlet plot

Foi útil?

Solução

I assume you get the following error message:

'opts' is deprecated. Use 'theme' instead. (Deprecated; last used in version 0.9.1)
theme_rect is deprecated. Use 'element_rect' instead. (Deprecated; last used in version 0.9.1)

If so, this should be stated in your question.

Using the current version of ggplot2 (0.9.3.1) and theme() instead of opts(), this script:

ggplot(data = dat, aes(x = item, y = value, ymin = 0, ymax = value)) +
  geom_point(colour = "blue") + 
  geom_linerange(colour = "blue") + 
  facet_wrap(~draw, ncol = 5) + 
  scale_y_continuous(lim = c(0, 1)) +
  theme_bw() +
  theme(panel.border = element_rect(colour = "black"))

...gives this plot:

enter image description here

Is this what you want?

You may also wish to check the scales argument in ?facet_wrap, and coord_cartesian as an alternative to set limits in scale_y_continuous

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top