I'm working with an asc file in R and trying to run it through some GIS processing on a script that was written by someone else. The current chunk of code I'm working on is
asc <- (raster(inputRas))
asc.extent <- extent(asc)
head <- read.ascii.grid.header(inputRas)
writeRaster(asc, "outputRas", format="SAGA", overwrite=TRUE)
which works until the last line. It's failing here because my raster is in rectangular coordinates, which SAGA doesn't like. I've spent a lot of time googling and trying different functions, but nothing has worked that didn't cause other problems down the line. I considered using projectRaster() for a while because the resolution can be changed within it, but I don't actually want to change the projection. Any help would be appreciated, thanks.
Instead of raster::projectRaster, you can use raster::resample
Related
I am trying to use the default plot() function in R to try and plot a shapefile that is about 100MB, using RStudio. When I try and plot the shapefile, the command doesn't finish executing for around 5 minutes, and when it finally does, the plotting window remains blank. When I execute the same process exactly in VS Code, the plot appears almost instantly, as expected.
I have tried uninstalling and reinstalling RStudio with no success.
I can't speak for what VStudio does, but I can guarantee that plotting 100MB worth of data points is useless (unless the final plot is going to be maybe 6 by 10 meters in size).
First thing: can you load the source file into R at all? One would hope so since that's not a grossly huge data blob. Then use your choice of reduction algorithms to get a reasonable number of points to plot, e.g. 800 by 1600, which is all a monitor can display anyway.
Next try plotting a small subset to verify the data are in a valid form, etc.
Then consider reducing the data by collapsing maybe each 10x10 region to a single average value, or by using ggplot2:geom_hex .
I have been trying to perform some of the raster related operations using R and whenever I am loading raster files in R in the plot window it is being displayed at a different scale which is hard to notice. I'm a little confused about how to bring it back to a standard size. As I'm new to the R language I'm not able to figure it out. Little help would be appreciated. Thanks in advance.
It was due to the default values set in par() function. By changing the "mar" parameter in the function I was able to resize it to my own convenience.enter image description here
This is not an specific question, but mostly a "looking for suggestions", since any kind of answer is welcome.
I built a huge website using pure shiny in R, but a really small thing is bothering me..
I'm plotting some elements over an image, let's say.. rectangles (could be anything), and interact with those elements using their position on the image. One of the actions is deleting some of those elements, but -as far as my understanding of R plotting system is- that can't be done, since an element plotted in R can't be removed, so my workaround is basically "plotting everything else" but the element i just deleted.
So, my question is, is there any way to "remove" an object in a plot without having to replot everything else (basically not making a new plot with everything but the deleted element)?
Thanks in advance!
I'm trying to do a noise removal by FFT in R. The trouble I'm having is that I get a y-axis shift during the process and I'm not sure what the cause is. I have read up on FFT and used this resource as a guide. See below for the code I have been executing as well as sample graphics of the result. Here is a dropbox link to the csv file. data.csv
data=read.csv('data.csv')
plot(data,type='l')
#FFT filtration function
fft.filter=function(data,threshold){
temp=fft(data)
temp[threshold:length(data)-threshold]=0+0i
temp=Re(fft(temp,inverse=TRUE)/length(temp))
return(temp)
}
data2=data
data2$Signal=fft.filter(data2$Signal,100)
Unfiltered Plot:
Filtered Plot:
As the images show, the data scaling looks fine, I'm just getting a shift that I don't think I should be. The FFT function is working to remove noise from the series.
There is a problem with the indexing. It is indexing from 0 to length(data)-threshold, whereas you want threshold:(length(data)-threshold) I believe. Change the indexing line to
temp[threshold:(length(data)-threshold)]=0+0i
I'd like to create a heat map in R that I want to use on a website. I stumbled upon the SVGAnnotation package which seems to be very nice to process SVG graphics in R to make them more interactive. First, I was planning to add tool tips for each cell in the heatmap - if the user hovers over the cell, the value of this cell should pop up. However, I am fighting with SVGAnnotation for more than 3 hours now, reading and trying things, and I can't get it to work.
I would appreciate any help on the SVGAnnotation tool tip function. But I would also very much appreciate alternatives to SVGAnnotation to add some activity to my R SVG heatmap.
So, what I have got so far looks like this:
library(SVGAnnotation)
data(mtcars)
cars <- as.matrix(mtcars)
map <- svgPlot(heatmap(cars))
addToolTips(map, ...) # problem
saveXML(map, "cars.svg")
My problem is the addToolTips function itself, I guess. Intuitively, I would simply insert the data matrix, i.e., cars, but this does not work and R gets stuck (it's calculating, but doesn't return anything, I waited 50 minutes)
EDIT:
After some more online research, I found a good example of what I want to achieve: http://online.wsj.com/article/SB125993225142676615.html#articleTabs=interactive
This heat map looks really great, and the interactive features (tool tips) work very well. I am wondering how they did that. To me, it looks like the graphic was done in R using the ggplot package.
I wrote a command line tool that can do exactly that if you are still interested to add tool tips to your heat map. It runs in Windows/Linux/MacOS terminals. All you need as input is the heat map as svg file and the data table/matrix that you used as input to create your heat map as csv or other text file.