0

I am trying to make a stacked area graph in ggplot2:

Zooplankton<-read.table("clipboard".header=TRUE)

TransZoop   Zoop    DensZoop
0   Copepoda    0.066
0   Nauplii 0.425
0   Cladocera   0.199
0   Rotifera    0.269
0   others  0.041
217 Copepoda    0.045
217 Nauplii 0.567
217 Cladocera   0.110
217 Rotifera    0.267
217 others  0.011
462 Copepoda    0.046
462 Nauplii 0.325
462 Cladocera   0.522
462 Rotifera    0.090
462 others  0.017
848 Copepoda    0.043
848 Nauplii 0.020
848 Cladocera   0.928
848 Rotifera    0.009
848 others  0.000
1248    Copepoda    0.019
1248    Nauplii 0.013
1248    Cladocera   0.964
1248    Rotifera    0.003
1248    others  0.000
1765    Copepoda    0.017
1765    Nauplii 0.003
1765    Cladocera   0.980
1765    Rotifera    0.000
1765    others  0.000
3216    Copepoda    0.030
3216    Nauplii 0.003
3216    Cladocera   0.962
3216    Rotifera    0.004
3216    others  0.000

When I use the command:

Z<-ggplot(Zooplankton,aes(x=TransZoop,y=DensZoop,group=Zoop,fill=Zoop))+geom_area(position="fill")+scale_fill_brewer(palette="Dark2")

It turns out like this: enter image description here

But when I try to change some graphical parameters, the plot disappears:

Z<-ggplot(Zooplankton,aes(x=TransZoop,y=DensZoop,group=Zoop,fill=Zoop))+geom_area(position="fill")+scale_fill_brewer(palette="Dark2") + labs(list(x="Distance from margin (m)",y="Zooplankton"))+theme(axis.text.x=element_text(size=30),axis.text.y=element_text(size=30),axis.title.x=element_text(size=30),axis.title.y=element_text(size=30,angle=90),legend.text=element_text(size=30),legend.title=element_blank(),legend.key.size=unit(2,"cm"),legend.key=element_rect(colour="black",linetype="solid",size=1.5),panel.border=element_rect(colour="black"))

enter image description here

What am I doing wrong?

closed as off-topic by Vince, Kazuhito, Andre Silva, Kadir Şahbaz, ahmadhanb Oct 19 '18 at 6:19

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions relating to general IT or with no clear GIS component, are off-topic here but can be researched/asked at Stack Overflow (software development), Super User (computing hardware and software), Database Administrators (relational databases) and other SE sites" – Vince, Kazuhito, Andre Silva, Kadir Şahbaz, ahmadhanb
If this question can be reworded to fit the rules in the help center, please edit the question.

  • Welcome to GIS StackExchange, user130200 !. Unfortunately your question seems a bit off-topic, since the GIS component in your question is only Distance from margin (m) and it is rather weak. For your convenience I posted an answer, but voted to close at the same time... It can be asked in StackOverflow. – Kazuhito Oct 18 '18 at 18:03
1

The culprit is panel.border=element_rect(colour="black"). Add fill=NA to prevent it from hiding your plot.

ggplot(Zooplankton,aes(x=TransZoop,y=DensZoop,group=Zoop,fill=Zoop))+
  geom_area(position="fill")+
  scale_fill_brewer(palette="Dark2") + 
  labs(x="Distance from margin (m)",y="Zooplankton")+
  theme(axis.text.x=element_text(size=30),
        axis.text.y=element_text(size=30),
        axis.title.x=element_text(size=30),
        axis.title.y=element_text(size=30,angle=90),
        legend.text=element_text(size=30),
        legend.title=element_blank(),
        legend.key.size=unit(2,"cm"),
        legend.key=element_rect(colour="black",linetype="solid",size=1.5),
        panel.border=element_rect(colour="black", fill= NA)                 ### fill= NA ### 
        )

enter image description here

Not the answer you're looking for? Browse other questions tagged or ask your own question.