Categories
Development

Creating two lines for each item in legend with a superscript

I’d like to create a plot in R and I have two independent variables which I’d like to list each levels of the factors in the legend. The code I have now is a for loop. I’d like to have each item of the legend shown with the temperature and sediment shown on first time […]

Categories
Development

Browser-friendly way of drawing rectangles on top of image R Shiny

I have written a shiny app that allows the user to draw rectangles on top of an image (minimal reproducible example below). The problem with my current approach is that every time a rectangle is added, a new image is created, written to disk, and rendered (sent to the user’s browser). This takes quite some […]

Categories
Development

Browser-friendly way of drawing rectangles on top of image R Shiny

Minimal reproducible example of a shiny app that draws rectangles on top of an image: library(shiny) library(png) library(RCurl) myurl = ‘https://raw.githubusercontent.com/Tixierae/deep_learning_NLP/master/CNN_IMDB/cnn_illustration.png’ my_img = readPNG(getURLContent(myurl)) img_height = dim(my_img)[1] img_width = dim(my_img)[2] server = function(input, output) { observe({ outfile = tempfile(tmpdir=’./’, fileext=’.png’) png(filename=outfile,width=img_width,height=img_height) par(mar=c(0,0,0,0),xaxs=’i’, yaxs=’i’) plot(NA,xlim=c(0,img_width),ylim=c(0,img_height)) rasterImage(my_img,0,0,img_width,img_height) if (!is.null(input$image_brush)){ b_in = lapply(input$image_brush,as.numeric) if (!is.null(b_in$xmin)){ rect(b_in$xmin,img_height-b_in$ymax,b_in$xmax,img_height-b_in$ymin,border=’green’,lwd=5) } } […]

Categories
Development

quarter circles ggplot-s with nonexisting points

I try to use ggplot to plot quarted circles to visualize contour plots but I get misconfigured plot using geom_area (following this tutorial on stacked area with ggplot2) The code I tried reads library(ggplot2) library(dplyr) N <- 1E2 r <- rev(c(1,2,4,7)) maxXY = max(r)+.25*max(r) grupp <- c(“0″,”0.25″,”0.5″,”0.75”) datalist = list() plot(0,0,xlim=c(0,maxXY),ylim=c(0,maxXY)) for (i in 1:length(r)) […]

Categories
Development

How to update different types of distribution estimating same value in R?

we are trying to create a distribution that estimates pathogens presence on vegetables. This was done using different methods, each providing a distribution: – method S (from sludge concentration) is best fitted by weibull(1.55, 8.57) – method SO (from soil) is best fitted by logN(0.68, 0.63) – method F (from field data) PERT(0.093, 0.34, 0.52) […]

Categories
Development

How to fix “unexpected symbol” in 100% Stacked Bar Chart Code

I am attempting to create a 100% Stacked Bar Chart for my data set however I keep getting the error message “unexpected symbol in”. I have tried removing spaces and double checked that everything is spelled correctly but the error keeps popping up and I am not entirely sure what is wrong. Can anyone help? […]

Categories
Development

How to plot regression line only through data range

I am having problems plotting a regression line that only covers the range of the x values. The only solution I get to work is similar to using abline, which produces regression lines through the entire plot. My data frame ‘rates’: structure(list(subpop = structure(1:13, .Label = c(“BB”, “DS”, “FB”, “GB”, “KB”, “LS”, “MC”, “NB”, “NW”, […]

Categories
Development

R: Unexpected cropping in mfrow graph

I am trying to create a 3×3 multiplot with mfrow. The layout is correct, however the single plots seem to contain only part of the data. The code I use to produce the graph is timing = c(10,30,50,75,100,125,200,250,300) pdf(“Figure.pdf”) par(mfrow=c(3,3)) for(t in timing) { dat = subset(inventory.data,Time==t) plot(NA, xlim=c(0,200),ylim=c(0,200), xlab = NA, ylab = NA, […]

Categories
Development

Is it possible to analyse a spatial point pattern given another, underlying, spatial point pattern in R

I want to analyse the type of spatial pattern shown by an animal (i.e. random, clustered, uniform) taking into consideration the underlying spatial pattern of it’s available habitat. The animals in question roost in trees, so a standard analysis of the animal spp will always show a clustered distribution (i.e. clustering around trees), but I […]