Can not customize points in rgl plot3D - r

I am trying to customize points in my 3D pca chart, but whatever I do, they just remain as points, and their size can not be changed:
with(df_new, plot3d(PC1,PC2,PC3, col = color, type="p", radius = 0.5))
sessionInfo():
R version 3.5.1 (2018-07-02)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS High Sierra 10.13.4
Matrix products: default
BLAS:
/System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/
vecLib.framework/Versions/A/libBLAS.dylib
LAPACK:
/Library/Frameworks/R.framework/Versions/3.5/Resources/lib/
libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats4 parallel stats graphics grDevices utils
datasets methods base
Any suggestions would be greatly appreciated

I think that you are using radius to change the size of the points, but radius only applies when you print spheres using type="s". To change the size of the points, use size.
with(df_new, plot3d(PC1,PC2,PC3, col = color, type="p", size = 0.5))
Although size=0.5 will be very small.

Related

Why the graph is not proper in R?

I wanted to plot the graph from the adjacency matrix. As a first step, I have tried the following code.
set.seed(1)
library('igraph');
adjm1<-matrix(sample(0:1,100,replace=TRUE,prob=c(0.9,01)),nc=10);
g1<-graph.adjacency(adjm1);
plot(g1)
But it gave me, the following graph.
What is the mistake here?
PS: I am using
Rstudio Version 1.1.442
R version 3.4.4 (2018-03-15)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
It seems for whatever reason the default arrow size on your system is too large. One can specify the arrow size in the plot statement. Example: edge.arrow.size = 0.5
set.seed(1)
library('igraph');
adjm1<-matrix(sample(0:1,100,replace=TRUE,prob=c(0.9,01)),nc=10);
g1<-graph.adjacency(adjm1);
plot(g, edge.arrow.size = 0.1)
From similar question: igraph - plotting directed network creates triangular edges

How to Plot Graphs in Julia 0.5?

I'm learning Julia by working through Chris Rackauckas' Introduction and I've come across a task that requires me to plot some data. I couldn't manage to get the Plots module to import so I tried a simple test:
using Plots
x = 1:10
y = 0.5*x + 3
plot(x, y)
When I first run this piece of code using the Juno IDE I get an error:
LoadError: LoadError: LoadError: syntax: unhandled expr (error #<julia: Main.Base.MethodError(f=FixedPointNumbers.#floattype(), args=(Main.FixedPointNumbers.FixedPoint{UInt8, 8},))>)
in include_from_node1(::String) at .\loading.jl:488 (repeats 2 times)
in eval(::Module, ::Any) at .\boot.jl:234
in require(::Symbol) at .\loading.jl:415
in include_string(::String, ::String) at .\loading.jl:441
in include_string(::Module, ::String, ::String) at 2
This refers to the using statement in my snippet. This error does not appear when I run from the REPL. The version info is as follows:
Julia Version 0.5.0
Commit 3c9d753 (2016-09-19 18:14 UTC)
Platform Info:
System: NT (x86_64-w64-mingw32)
CPU: Intel(R) Core(TM) i7-4810MQ CPU # 2.80GHz
WORD_SIZE: 64
BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell)
LAPACK: libopenblas64_
LIBM: libopenlibm
LLVM: libLLVM-3.7.1 (ORCJIT, haswell)
I currently have version 0.10.3 of Plots installed.
If you provide some version/platform information by sharing the output of versioninfo(), one can help you better.
For instance, the below excerpt
Pkg.add("Plots")
using Plots
plotly() # this backend is installed by default
x = 1:10
y = 0.5*x + 3
plot(x, y)
works well under
Julia Version 0.5.0
Commit 3c9d753* (2016-09-19 18:14 UTC)
Platform Info:
System: Linux (x86_64-pc-linux-gnu)
CPU: Intel(R) Core(TM) i7-3720QM CPU # 2.60GHz
WORD_SIZE: 64
BLAS: libopenblas (NO_LAPACK NO_LAPACKE NO_AFFINITY SANDYBRIDGE)
LAPACK: liblapack
LIBM: libm
LLVM: libLLVM-3.7.1 (ORCJIT, ivybridge)
Maybe you should conisder Pkg.add("PyPlot") or a similar backend, and try it again later?
To work with the Run File command using the Juno package in the Atom IDE the plot has to be assigned to a variable and passed to the display function.
using Plots
pyplot()
x = 1:100
y = 0.5*x + 10
println(y)
graph = plot(x, y)
display(graph)
This will display the graph in Juno's Plots window. In the comments Arda Aytekin suggested that pyplot(display=true) or graph = plot(x, y, display=true) could be used, which leads to the graph displaying in a separate pyplot window.

EBImage feature names

Can anyone explain what is being used to compute different features within computeFeatures?
I get the naming convention being applied that is spelled out in ? computeFeatures. I don't understand the .0., .a. and .Ba. labels.
For example:
> library(EBImage)
> y = readImage(system.file("images", "nuclei.tif", package="EBImage"))[,,1]
> x = thresh(y, 10, 10, 0.05)
> x = opening(x, makeBrush(5, shape='disc'))
> x = bwlabel(x)
> ft = computeFeatures(x, y, xname="nucleus")
> colnames(ft)
[1] "nucleus.0.m.cx" "nucleus.0.m.cy"
[3] "nucleus.0.m.majoraxis" "nucleus.0.m.eccentricity"
<snip>
[11] "nucleus.0.s.radius.max" "nucleus.a.b.mean"
[13] "nucleus.a.b.sd" "nucleus.a.b.mad"
<snip>
[51] "nucleus.Ba.b.mean" "nucleus.Ba.b.sd"
[53] "nucleus.Ba.b.mad" "nucleus.Ba.b.q001"
[55] "nucleus.Ba.b.q005" "nucleus.Ba.b.q05"
<snip>
My guess is nucleus.0.* features use only the data from the binary masks contained in x. So nucleus.0.m.cy is the y-axis centroid computed using the binary data. There are also nucleus.a.m.cy and nucleus.Ba.m.cy but it is unclear how these computations are different (they are extremely correlated but not identical).
I also suppose the .a. and .Ba. use the intensity values in y but the details are vague. Features like nucleus.a.b.mean and nucleus.Ba.b.mean are similar (~.80 corr) but not the same. I assume that they estimate the mean y intensity of objects defined by the labels in x but the difference is unclear.
Is there any documentation on this?
Thanks,
Max
> sessionInfo()
R Under development (unstable) (2014-08-23 r66461)
Platform: x86_64-apple-darwin10.8.0 (64-bit)
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] EBImage_4.7.16
loaded via a namespace (and not attached):
[1] abind_1.4-0 BiocGenerics_0.11.4 grid_3.2.0
[4] jpeg_0.1-8 lattice_0.20-29 locfit_1.5-9.1
[7] parallel_3.2.0 png_0.1-7 tiff_0.1-5
[10] tools_3.2.0
Have you seen the documentation here: AnalysisWithEBImage
This seems to be the most in depth document that discusses the package. Have you tried contacting the author Grégoire Pau directly? Im sure if you google him you can find him.
As a disclaimer, I know nothing of your field, but by looking at the function I can make a pretty good guess at what is going on. I recommend that you use debugonce(computeFeatures) and then run ft = computeFeatures(x, y, xname="nucleus"). You can step through each line of the code (type Q) to exit, and see what is going on.
As you noted, the documentation states:
Features are named x.y.f, where x is the object layer, y the
reference image layer and f the feature name.
In your example computeFeatures has generated values for three reference layers (a, aB, and 0). The documentation mentions that if you don't name your reference layers, they will just be given the letters of the alphabet, so in your case you had one reference layer, and it is called a. I believe the 0 means that it uses no reference layer.
From looking at the source code, it appears that for every layer i, a B_i layer is created. It appears to pass a hardcoded filter over each layer as you can see in this code, found in the expandRef function (the comments are mine):
# Hard code a filter
blob = gblob(x0 = 15, n = 49, alpha = 0.8, beta = 1.2)
# Filter using the fast 2D FFT convolution product.
bref = lapply(ref, function(r) filter2(r, blob)/2)
# Name it "B" and then the layer name
names(bref) = paste("B", names(ref), sep = "")
I don't know exactly what you are trying to do here, but you can see visually what this filter is doing. Here is your x (you can just run display(x) to see it):
Here is your reference (y):
Here is what the hardcoded filter looks like:
And this is what the hardcoded filter does to y:
So, to summarize: everything with 0 is comparing to a no reference, everything with a is comparing directly to y as a reference, and everything with aB is comparing to a filtered version of y.

How can I increase the map size in a plot?

I want to plot points in an openstreetmap. To determine a suitable range for the map I want to use min() and max() and increase the size by 10%:
library(OpenStreetMap)
coords <- data.frame(cbind(c(-2.121821, -2.118570, -2.124278),
c(51.89437, 51.90330, 51.90469)))
topleft <- c(max(coords[,2]) + 0.1 * max(coords[,2]),
min(coords[,1]) - 0.1 * min(coords[,1]))
bottomright <- c(min(coords[,2]) - 0.1 * min(coords[,2]),
max(coords[,1]) + 0.1 * max(coords[,1]))
map <- openproj(openmap(topleft, bottomright, zoom = "16", type="osm"))
When I now try to create the map R eats up all my resources and I have to kill the process. Is there a better way to achieve this?
R version 3.0.1 (2013-05-16)
Platform: x86_64-unknown-linux-gnu (64-bit)
other attached packages:
[1] ggplot2_0.9.3.1 OpenStreetMap_0.3.1 rgdal_0.8-14 raster_2.2-12 sp_1.0-14
[6] rJava_0.9-6
You're extending the range incorrectly, as you'll see if you have a look at the computed values of topleft and bottomright.
A less error-prone approach might use the function extendrange() (which is used by many R plotting functions to add a little buffer around the most extreme points in the plot).
xx <- extendrange(coords[[1]], f=0.10)
yy <- extendrange(coords[[2]], f=0.10)
tl <- c(max(yy), min(xx))
br <- c(min(yy), max(xx))
map <- openproj(openmap(tl, br, zoom="16", type="osm"))
plot(map)

Help in using rgl package

I installed rgl package with the option --disable-libpng. I tried generating a 3d scatter plot and it crashes. Please help me in resolving this
This is the code i am running
library(rgl)
open3d()
x <- sort(rnorm(1000))
y <- rnorm(1000)
z <- rnorm(1000) + atan2(x,y)
plot3d(x, y, z, col=rainbow(1000))
It crashes with below messages
*** caught segfault ***
address (nil), cause 'memory not mapped'
Traceback:
1: .External(rgl_par3d, args)
2: par3d(skip)
3: plot3d.default(x, y, z, col = rainbow(1000))
4: plot3d(x, y, z, col = rainbow(1000))
Possible actions:
1: abort (with core dump, if enabled)
2: normal R exit
3: exit R without saving workspace
4: exit R saving workspace
Selection:
Here is the information from sessionInfo()
> sessionInfo()
R version 2.11.1 (2010-05-31)
x86_64-unknown-linux-gnu
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=C
[5] LC_MONETARY=C LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] rgl_0.92.798
This is from the sysname command
x86-64_linux_2.6.16_ImageSLES10SP3-3
Some more info:
I am able to generate a surface plot from some code in R: Plotting a 3D surface from x, y, z
Here is the code
x <- seq(-10, 10, length.out = 50)
y <- x
rotsinc <- function(x,y) {
sinc <- function(x) {
y <- sin(x)/x;
y[is.na(y)] <- 1;
y
}
10 * sinc( sqrt(x^2+y^2) )
}
z <- outer(x, y, rotsinc)
surface3d(x, y, z)
I tried demo(rgl) and that is also crashing with similar message. I want to generate 3d plots, which other package do you recommend? ggplot?
The rgl package makes use of possible hardware acceleration in your graphics card via its driver.
This is unfortunately entirely dependent on the driver. I have been using rgl for animated visualization for a number of years---see eg this visualization of option analytics surfaces from 2005---which I can assure you crashed for no good reason on some machines and runs on others. You really should try on a different machine with a different driver before making any firm conclusions.
Computers use hardware, and sometimes the hardware bites. I can your code fine on one of my machines. Another is dual-screen and hence without GL extension so it won't. Did I mention hardware bites?
I tested the exact same code on my system, and it worked perfectly.
Whatever the issues were, they have probably been fixed.
Test 1:
library(rgl)
demo(rgl)
Test 2:
library(rgl)
open3d()
x <- sort(rnorm(1000))
y <- rnorm(1000)
z <- rnorm(1000) + atan2(x,y)
plot3d(x, y, z, col=rainbow(1000))
My system is Windows 7 x64 running R v2.14.2. Tested under two IDEs, namely Revolution R and RStudio.

Resources