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

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?

Related

How to plot 3 different time-series with "actual" values rather than a density plot as ridgeline plots (formerly known as Joyplots) in R?

I would like to plot ridgeline plots of 3 different timeseries with same axes with actual values, but NOT a density plot as ridgeplots generally show.
Tried using Henrik Lindberg's code here : https://github.com/halhen/viz-pub/tree/master/sports-time-of-day
It does what it is supposed to do, but can not produce smoothing.
Also tried the ggridges manual codes (below)
ggplot(df,aes(x = time, y = activity, height = p)) + geom_density_ridges()
ggridges produces density plots, not as a timeseries as I want it to be. Henrik's code produces desired timeseries, but without the smoothing as I wanted from a ridgeplot.

changing plot dimensions in ggplot2 with one categorical variable

I am trying to plot data with a categorical x-axis variable and a continuous y-axis variable. The current plot is shown below:
A am trying to alter the height of the y-axis to make the plot taller and thinner. I know you can do this kind of thing with a continuous variable vs. continuous variable scatterplot using coord_fixed(), e.g.:
However, this works on the numeric ratios of the x and y data, which doesn't apply if one variable is categorical. Trying coord_fixed on my data with any input seems to just scale the plot exactly to the plot area:
Trying to adjust the canvas at the ggsave phase just adds white space around the plot, rather than changing the plot shape itself, which isn't what I'm looking for either:
ggsave(filename = paste(imgSaveDir,'RT_data_summ.png',sep=""),width=7,height=10)
Any help is appreciated!

Label outliers in an scatter plot

I've plot this graphic to identify graphically high-leverage points in my linear model.
Given the variable "NOMBRES" of the data set which my model uses, I've tried to plot all the points of my graphic but it gets illegible. Here's the code I ran:
> plot(hatvalues(tmodel),residuals(tmodel))
> text(hatvalues(tmodel),residuals(tmodel),labels=DSET$NOMBRES)
So I would like to plot just the points with leverage(hat value) above 0.05 using the label "DSET$NOMBRES".
Identify high-leverage points according to your definition:
hlev <- which(hatvalues(tmodel)>0.05)
Add numeric labels to the graph:
text(hatvalues(tmodel)[hlev], residuals(tmodel)[hlev],
labels=DSET$NOMBRES[hlev])

Extracting one plot from the plot function in geoR

I am using the geoR package, and I would like to display only one of the graphs obtained when using the plot function. Using a dataset provided with the package:
library(geoR); data(elevation)
plot(elevation)
This gives 4 plots on a 2 x 2 grid as in below. I would like to use the bottom right plot alone, but I am not sure how to get this plot alone.
So I tried plotting it from scratch:
axExFact <-1.1 # to set fitting y-axis limits
ymax <- max(c(0, signif(max(elevation[[2]])*axExFact, digits=1)))
ymin <- min(c(0, signif(min(elevation[[2]])*axExFact, digits=1)))
with(elevation, hist(data, main='Plot', xlab = 'Value ',cex.lab=1.25, font.lab=2,ylim=c(ymin, ymax)))
Though I can get the y-axis limits adjusted to fully cover the extent of the data, I am unable to add a density estimate along the histogram. Thought it could be done with lines(density(as.numeric[[elevation]])), but it doesn't work.
So it would be a lot easier to just get the graph obtained with the plot function. Then the only problem would be to adjust the y-axis. Any suggestions would be welcomed.

Scatterplot axis labels are wrong when plotting dates

I am trying to do a scatter plot of 2 time series data - the data is stored in a data frame. The background of the image is quite grainy and axis labels are not visible when I do:
ggplot(data=dat,aes(x,y))+geom_point()
With below, I get only dark vertical lines:
plot(dat$x,dat$y)
plot() and ggplot() did work after applying as.numeric() to the data(as below) but the axis labels are indices[1,2,...] and not the range of actual values.
plot(as.numeric(dat$x),as.numeric(dat$y))
ggplot(data=dat,aes(as.numeric(x),as.numeric(y)))+geom_point()
I cannot post the images here as I am new to this forum.
By default, the data was getting converted into factor while converting from matrix to data.frame. Below code fixed it.
data.frame(mydata,stringsAsFactors = FALSE)

Resources