I'm trying out a basic plot, but something about the way I subset my data
leads to problems with the plot.


Here is the first bit of my data set

year,date,location,quadrat_juvenile,photo_location,photo_exists,genus,count,divers
2005,2005-04-30, 1 Fringing Reef,1, 1 Fringing Reef Coral Transect Pole 1-2
Quadrat 1,t,Acanthastrea,0,HP+MEM
2005,2005-04-30, 1 Fringing Reef,1, 1 Fringing Reef Coral Transect Pole 1-2
Quadrat 1,t,Acropora,0,HP+MEM
2005,2005-04-30, 1 Fringing Reef,1, 1 Fringing Reef Coral Transect Pole 1-2
Quadrat 1,t,Astreopora,0,HP+MEM
2005,2005-04-30, 1 Fringing Reef,1, 1 Fringing Reef Coral Transect Pole 1-2
Quadrat 1,t,Cyphastrea,0,HP+MEM
2005,2005-04-30, 1 Fringing Reef,1, 1 Fringing Reef Coral Transect Pole 1-2
Quadrat 1,t,Favia,0,HP+MEM
2005,2005-04-30, 1 Fringing Reef,1, 1 Fringing Reef Coral Transect Pole 1-2
Quadrat 1,t,Fungia,0,HP+MEM
2005,2005-04-30, 1 Fringing Reef,1, 1 Fringing Reef Coral Transect Pole 1-2
Quadrat 1,t,Gardinoseris,0,HP+MEM
2005,2005-04-30, 1 Fringing Reef,1, 1 Fringing Reef Coral Transect Pole 1-2
Quadrat 1,t,Herpolitha,0,HP+MEM
2005,2005-04-30, 1 Fringing Reef,1, 1 Fringing Reef Coral Transect Pole 1-2
Quadrat 1,t,Leptastrea,0,HP+MEM
2005,2005-04-30, 1 Fringing Reef,1, 1 Fringing Reef Coral Transect Pole 1-2
Quadrat 1,t,Leptoseris,0,HP+MEM
2005,2005-04-30, 1 Fringing Reef,1, 1 Fringing Reef Coral Transect Pole 1-2
Quadrat 1,t,Lobophyllia,0,HP+MEM
2005,2005-04-30, 1 Fringing Reef,1, 1 Fringing Reef Coral Transect Pole 1-2
Quadrat 1,t,Millepora,0,HP+MEM
2005,2005-04-30, 1 Fringing Reef,1, 1 Fringing Reef Coral Transect Pole 1-2
Quadrat 1,t,Montastrea,0,HP+MEM

I need to breakdown the data before I can plot it, so this is the stepwise
code I use:

Juv=read.csv("juvenile_density_20110506.csv")
Juv$count[Juv$count<0]<- NA #Missing data is imputed as negative data, so
first label it as NA
JuvFor=subset(Juv,(location==" 2 Outer 10 m") | (location==" 1 Outer 10
m")) #Subset the data of interest
Juv_Sum_by_quad=aggregate(count~year+location+quadrat_juvenile,data=
JuvFor,sum) # Calculate sum of each quadrat
Juv_Avg=aggregate(count~year+location,data=Juv_Sum_by_quad, mean)
#Calculate yearly means

So far so good.....


I thought I could do this:

plot(Juv_Sum1$year, Juv_Sum1$count,type="L")

But not only do I get odd separate lines as opposed to a time series line
plot, but I the first tick mark on the x-axis lists the amount of rows in
my data. I can fix it by saving the final object as a .csv and reloading it
the data- but that defeats the whole purpose. Can anyone explain why I get
this plot result?

Looking through past posts I found that I can get away with just plotting
the y-axis. And if I modify the x axis separately I can get the plot I'm
looking for.

plot(Juv_Sum1$count,xaxt="n")
axis(1,at=1:length(Juv_Sum1$year),labels=Juv_Sum1$year)


But I'm concerned about why my data subsets are giving me odd results in
the first place, especially as I move on into more complicated bits of code.

Thanks for all your wisdom,

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to