Closed prashgeo87 closed 4 years ago
Hi @prashgeo87, you're welcome.
This looks like a problem with the way the nlStats are defined. You have:
nlStats=list(list("sum", "median", na.rm = TRUE))
which is translated as a call to the sum
function with arguments median
and na.rm=TRUE
which is incorrect. For multiple nlStats specify a list with each function in its own sub-list with corresponding arguments. Try this instead to calculate mean and median:
nlStats = list(list("sum", "na.rm = TRUE"), list("median", na.rm = TRUE))
Hi Chrisvwn, Thanks a lot, I have updated the code but now I am stuck with new error, please help me.
Optionally plot the data
library(ggplot2) library(plotly)
Attaching package: ‘plotly’
The following object is masked from ‘package:ggplot2’:
last_plot
The following object is masked from ‘package:stats’:
filter
The following object is masked from ‘package:graphics’:
layout
melt the stats into key-value format for easy multi-line plotting with ggplot2
highestAdmLevelStats <- melt(highestAdmLevelStats,
- id.vars = grep("NL_", names(highestAdmLevelStats),
- invert=TRUE),
- variable.name = "nlPeriod",
- value.name = "radiancesum") Error in melt(highestAdmLevelStats, id.vars = grep("NL_", names(highestAdmLevelStats), : object 'highestAdmLevelStats' not found
extract date from the NL col names
highestAdmLevelStats$nlPeriod <- substr(highestAdmLevelStats$nlPeriod, 12, 17) Error in substr(highestAdmLevelStats$nlPeriod, 12, 17) : object 'highestAdmLevelStats' not found
extract date from the NL col names
highestAdmLevelStats$nlPeriod <- substr(highestAdmLevelStats$nlPeriod, 12, 17) Error in substr(highestAdmLevelStats$nlPeriod, 12, 17) : object 'highestAdmLevelStats' not found
format period as date
highestAdmLevelStats$nlPeriod <- ymd(paste0(substr(highestAdmLevelStats$nlPeriod, 1,4),
- "-",substr(highestAdmLevelStats$nlPeriod, 5,6), "-01")) Error in substr(highestAdmLevelStats$nlPeriod, 1, 4) : object 'highestAdmLevelStats' not found
plot 2nd admin level sums for the year
g <- ggplot(data = highestAdmLevelStats,
- aes(x=nlPeriod, y=radiancesum,
- color=highestAdmLevelStats[[2]])) +
- scale_x_date(date_breaks = "1 month", date_labels = "%Y-%m")+
- geom_line()+geom_point() + labs(color = names(highestAdmLevelStats)[2]) +
- xlab("Month") +
- ylab("Sum of Radiances") +
- ggtitle(paste0(unique(names(highestAdmLevelStats)[2]), " sum of radiances for ", ctry)) Error in ggplot(data = highestAdmLevelStats, aes(x = nlPeriod, y = radiancesum, : object 'highestAdmLevelStats' not found
print(g) Error in print(g) : object 'g' not found
quick conversion to interactive map with plotly
ggplotly(g)
Thanks and Regards
Please post the whole output beginning from the getCtryNlData
command
Hi Chrisvwn, I have attached the codes in txt format, Looking forward to your support. Thanks and Regards, Code_Share.txt
Hi @prashgeo87 this looks like the main error here:
Error in melt(highestAdmLevelStats, id.vars = grep("NL_", names(highestAdmLevelStats), : could not find function "melt"
Check that you have reshape2
installed and run library(reshape2)
first.
Closing this issue. Please reopen if you are still having a problem.
Hi Chrisvwn, Thanks for the coding... I am trying to replicate your mentioned codes in R software. But I am getting the following error,
Please help me solve this issue...
Thanks and Regards