Beeswarm with logarithmic X axis - r

I am trying to plot a "beeswarm" which is essentially a single-dimensional scatterplot
library(beeswarm)
data(breast)
beeswarm(breast$time_survival,horizontal=TRUE)
What I want to achieve is logarithmic transformation of the X axis.
Obviously, I can do beeswarm(log(breast$time_survival),horizontal=TRUE,method="hex") but it plots logarithmically transformed data and X axis no longer reperesents survival time numerically. Is there a way to directly affect the X axis? In regular scatterplot, I would do plot(breast$time_survival,log="x") but not sure how to behave with beeswarm

option for beeswarm is log=TRUE, not log="x"
library(beeswarm)
data(breast)
beeswarm(breast$time_survival,horizontal=TRUE, log=T)

Related

R plot with plotly: Changing value on scale for 2dHeatMap

I used the following lines to plot a heatmap with plotly in R:
plot_ly(data, x , y) %>% add_trace(type='histogram2dcontour')
I then obtained the following plot
The data actually looks like that on a scatter plot
As you can see, I lose a lot of points on the heatmap. I was wondering how I could manually set the scale for the colour of the heatmap for e.g. making it so that the colour changes every time the count increase by 10 instead of 100.
Otherwise, is there a better way to plot and visualize such data?

How to fix scaling problems in "plot_ly" function from the package plotly

I am trying to draw contour plots through plot_ly function from the package "plotly".But the scaling of x and y in the outcomes is different from what I have defined.
I could fix the problem with scaling. but the next problem is that for one of the contour plots, the values of z are complex! so how can I use plotly for complex values of z?

How does R decide the x and y axis of mosaicplot

I am curious how R decides x and y axis of mosaic plot?
data(HairEyeColor)
mosaicplot(HairEyeColor)
It puts the "Hair" at x-axis and "Eye" at the y-axis and break the Sex.
Is it predetermined?
What will happen if we have more than 5 variables and do the mosaic plot?
See: Mosaic Plot vignette
xlab, ylab: x- and y-axis labels used for the plot; by default, the
first and second element of names(dimnames(X)) (i.e., the name of the
first and second variable in X).

Add a curve to a log/log scatterplot

I have a scatterplot in a log/log space
plot(a,b,log="xy")
or in ggplot2
qplot(a,b,data="time",log="xy")
Now I would like to impose upon this scatter plot the curve f(x)=x*x+2. Butthe function woudl need to be plotted in the logarithmic space as well. How would I do this? Is there an way to do this in ggplot2?
As you guessed, curve is the command that you're looking for in base graphics.
#Make up some data
set.seed(0)
a <- 1:10
b <-(a^2+2)*exp(0.1*rnorm(10))
plot(a,b,log='xy')
curve(x^2+2,add=TRUE)
in ggplot2 world:
qplot(a,b,data=time)+stat_function(fun=function(x){x^2+2}) + coord_trans(xtrans = "log10",ytrans="log10")
from Plotting in R using stat_function on a logarithmic scale seems to do what you're after.

How to plot density of two datasets on same scale in one figure?

How to plot the density of a single column dataset as dots? For example
x <- c(1:40)
On the same plot using the same scale of the x-axis and y-axis, how to add another data set as line format which represent the density of another data that represents the equation of
y = exp(-x)
to the plot?
The equation is corrected to be y = exp(-x).
So, by doing plot(density(x)) or plot(density(y)), I got two separated figures. How to add them in the same axis and using dots for x, smoothed line for y?
You can add a line to a plot with the lines() function. Your code, modified to do what you asked for, is the following:
x <- 1:40
y <- exp(-x)
plot(density(x), type = "p")
lines(density(y))
Note that we specified the plot to give us points with the type parameter and then added the density curve for y with lines. The help pages for ?plot, ?par, ?lines would be some insightful reading. Also, check out the R Graph Gallery to view some more sophisticated graphs that generally have the source code attached to them.

Resources