Web Content Display

Web Content Display (CoastWatch User Forum)

The NOAA CoastWatch Forum provides information in several categories.  The information is relevant to CoastWatch products and software (https://coastwatch.noaa.gov)  and vary in technical details.  For questions and issues not addressed here,  start a thread in the appropriate category or contact the CoastWatch HelpDesk (coastwatch.info@noaa.gov).  Please note our Privacy Policy (https://www.noaa.gov/privacy.html) and that this is a public forum.  All information is voluntarily and anonymous submissions are accepted pending review prior to posting. 

Forums

Back

Help with plotting error message in R

JW
Jen Walsh, modified 3 Years ago.

Help with plotting error message in R

Youngling Posts: 7 Join Date: 6/12/17 Recent Posts

Hi,

I'm trying to make a map of chl-a for January 2019 around the Antarctic Peninsula. I've posted my code below, and everything seems fine until I try to plot it, and I get this error. I tried Googling it and I find posts related to raster, but I'm new to mapping in R and I don't know what they mean. Help! Please let me know if you need additional information to help me troubleshoot.

My error (comes after plotBBox):

Error in setValues(r, vals) : 
  length(values) is not equal to ncell(x), or to 1

My code:

xcoord<-ac.df$lon #ac.df is a data frame of lat, lon, and krill density along the Antarctic Peninsula
ycoord<-ac.df$lat

library(rerddapXtracto)


dataInfo<-rerddap::info("nesdisVHNSQchlaMonthly") #this comes from the ERDDAP ID in Polarwatch
dataInfo
parameter<-"chlor_a"
zcoord<-0 #dataInfo shows an altitude coordinate of 0, so you have to set your zcoord to 0
tcoord<-c("2019-01-02T12:00:00Z", "2019-02-01T12:00:00Z") #set the time period you're interested in
#now extract the data
apchl <- rxtractogon (dataInfo, parameter=parameter, xcoord=xcoord,ycoord=ycoord, tcoord=tcoord, zcoord=zcoord)
str(apchl)

#specify the time period of chl data 
apchl1<-apchl
apchl1$chla<-apchl1$chlor_a[,,2]
apchl1$time<-apchl1$time[2]

#plot
chlplot<-plotBBox(apchl1, plotColor = 'algae', maxpixels=100000)

CW
Cara Wilson, modified 3 Years ago.

RE: Help with plotting error message in R

Youngling Posts: 41 Join Date: 6/12/17 Recent Posts

Jen - 

I think you are getting confused with the different functions in this package.  You are calling rxtractogon which will extract all the data around a polygon that is defined by the points read in by xcoord and ycoord, which can be vectors of any length. The time coordnates input in tcoord should be just two points - the starting and ending points.  The beginning of your code references krill densities and indicates that you might want to use rxtracto, which is a function to match up x-y-t data points with the associated satellite data.  When calling that function xcoord, ycoord and tcoord must all be of the same length.   If the map you want to make is just a simple box then you don't have to use  rxtractogon, you can use rxtracto_3D which will retrieve a three dimensional box of data, and all you have to supply are the ranges of latitude, longitude and time, so xcoord, ycoord and tcoord should all be two element vectors.  

HTH 

Cara