Resizing plots in plotly (R) - r

Sorry if this question has already been answered but I can't find a solution.
I have a data frame which is imported from a .csv file. It has four columns. I want to plot a 3d scatter plot of the first two columns against the last column using Plotly.
The problem is that for some reason, the scatter plot does not automatically resize its axes to fit the plot space. So in this case I end up with a tall thin plot. The weird thing is that if I do an example with some random numbers, I don't get this problem.
Can anyone help me to get my scatter plot to fit to the window?
My data can be found at https://www.dropbox.com/s/ojwrezjker33x2b/Data.csv?dl=0
Basically I want to do:
library(plotly)
X<-read.csv("Data.csv")
plot_ly(x=X[,1],y=X[,2],z=X[,4],type='scatter3d',mode='markers')
And this results in a tall and thin scatter plot (sorry can't post an image cos I am new to the site).
I would like this to be a well-proportioned scatter plot that fits the window.
Thanks for any help.

The default setting for aspectmode is 'auto' and Plotly will try to keep the relative axis lenghts equal.
If you set aspectmode='cube' you should get a plot with identical absolute axes lengths.
plot_ly(x=X[,1],y=X[,2],z=X[,4],type='scatter3d',mode='markers') %>%
layout(scene=list(aspectmode='cube'))

Related

Cicular contour map using Plotly

I am trying to create contour plots of film thicknesses on a wafer using plotly, but would like the outputted plot to be a circle since it is a wafer instead of the default square. Do I have to somehow overlay a circle on to the plot and then exclude anything outside of it after the plot is generated? I prefer using plotly if possible since it looks nice. I've tried using ggplot as well but for some reason my data doesn't work with it since the x and y coordinates are apparently irregularly spaced. I've searched around but have not seen any results at least using R.
Thanks!

ggplot2: Is there a way to eliminate distortions of shapes when using geom_point and position_dodge?

I am making plots that have categorical x variables with multiple factors for each category. I use geom_point and position_dodge similar to this post: ggplot2: geom_point() dodge shape but NOT color. If you look closely at the plot created in that post you can see that when xVar=C the "+" points are not symetrical, in that the right and bottom lines are longer than the top and left. Perhaps this is not a big deal for simple plots, but I have a fairly complex plot. I have a 3*3 multi-plot using grid_arrange. This multi-plot has a total of 81 points and error bars for each of the points. The distorted points are not centered on many of the error bars, so this problem really stands out in my case. Perhaps this has something to do with using position_dodge with grid_arrange.
I've tried exporting the image as different file types (e.g., jpg, png, pdf).
Here is some code from the aforementioned link:
x=tibble(Color=c(rep('A',12),rep('B',12),rep('C',12)),
Shape=rep(c(rep('A',3),rep('B',3),rep('C',3),rep('D',3)),3),
xVar=rep(c('A','B','C'),12),
Value=rnorm(36))
ggplot(x,aes(xVar,Value,color=Color,shape=Shape))+
geom_point(position=position_dodge(width=.5))
ggplot(x,aes(xVar,Value,color=Color,shape=Shape,group=Shape))+
geom_point(position=position_dodge(width=.5))
I would like to have geom_point shapes that are not distorted.

How to move the legend to outside the plotting area in Plots.jl (GR)?

I have the following plot where part of the data is being obscured by the legend:
using Plots; gr()
using StatPlots
groupedbar(rand(1:100,(10,10)),bar_position=:stack, label="item".*map(string,collect(1:10)))
I can see that using the "legend" attribute, the legend can be moved to various locations within the plotting area, for example:
groupedbar(rand(1:100,(10,10)),bar_position=:stack, label="item".*map(string,collect(1:10)),legend=:bottomright)
Is there any way of moving the plot legend completely outside the plotting area, for example to the right of the plot or below it? For these kinds of stacked bar plots there's really no good place for the legend inside the plot area. The only solution I've been able to come up with so far is to make some "fake" empty rows in the input data matrix to make space with some zeros, but that seems kind of hacky and will require some fiddling to get the right number of extra rows each time the plot is made:
groupedbar(vcat(rand(1:100,(10,10)),zeros(3,10)),bar_position=:stack, label="item".*map(string,collect(1:10)),legend=:bottomright)
I can see that at there was some kind of a solution proposed for pyplot, does anyone know of a similar solution for the GR backend? Another solution I could imagine - is there a way to save the legend itself to a different file so I can then put them back together in Inkscape?
This is now easily enabled with Plots.jl:
Example:
plot(rand(10), legend = :outertopleft)
Using layouts I can create a workaround making a fake plot with legend only.
using Plots
gr()
l = #layout [a{0.001h}; b c{0.13w}]
values = rand(1:100,(10,10))
p1 = groupedbar(values,bar_position=:stack, legend=:none)
p2 = groupedbar(values,bar_position=:stack, label="item".*map(string,collect(1:10)), grid=false, xlims=(20,3), showaxis=false)
p0=plot(title="Title",grid=false, showaxis=false)
plot(p0,p1,p2,layout=l)

space points in a scatter plot in R

I am plotting a scatter plot in R, however I have many data points and they overlap. I want to have a plot where there no overlaps and maintain a reasonable size of the data . This is the image of the scatter. On the top side is where the data are clustered.
This is the code plot(data2,col="red",pch=21,cex=0.7)
Could you put a reproducible code to check.
One thing you can do is may be increase the space between y axis interval.

qcc pareto.chart: bars are squashed - how to adjust the y axis?

I've produced a pareto.chart using the QCC package in R. In the default plot, the Y axis is scaled too large & for that reason the bars are too small. Most of the plot is wasted to empty white space. I assume this is a result of the long tail (right-skew) in the data ?
How is it possible to re-scale the Y-Axis so that the bars of the chart will be taller and more prominent (and differences between the bars more visible) ?
This is my first question and I can't post images yet. Please follow the link to an illustration of the problem:
https://www.dropbox.com/s/t8bwhmoxmwl1aic/pareto-axis.png
Thanks!
Keith
If you type help(pareto.chart) you will see there is an option ylim to specify the limits if the y-axis. If you provide some sample data I could try it out.
Otherwise, try including in your function call
pareto.chart(..., ylim=c(0,10000))
and see if that rescales your y-axis.

Resources