I have a (21,100)-array and want to plot it as 2D-Histogram (heatmap).
If I plot it naively with histogram2d(A, nbins= 20) it only plots the first 21 points.
I tried to loop it, but then I had 100 histograms with 21 points.
Another idea would be to put the data in a (2100)-array but this seems like a bad idea.
Addition:
I have a scatter plot/data and want it shown as a heatmap. The more points in one bin the "darker" the color.
So I have 21 x-values each with 100 y-values.
Here it is a typical scenario for a heatmap plot:
using Plots
gr()
data = rand(21,100)
heatmap(1:size(data,1),
1:size(data,2), data,
c=cgrad([:blue, :white,:red, :yellow]),
xlabel="x values", ylabel="y values",
title="My title")
Related
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?
Image: plotted the relationship between 4 variables, resulting in 12 scatterplots
In the image above, I've got 12 scatterplots, but no axis labels making it a bit difficult to know what each scatterplot is showing.
I believe I can just use the xlab and ylab function to tell R what the axis labels should be if I only have 1 scatterplot. But if I have 12 scatterplots, is it possible to tell R to somehow use the appropriate heading from my csv file as the x-axis label and y-axis label for each plot?
Here is a screenshot of my data if it helps:
cheese csv screenshot
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.
I am trying to plot my two figures on the same page in R.
Two plots are: Scatter and bat plot
Used: par(mfrow=c(2,1))
p
s
where p is the bar plot and s is the scatter plot.
When I used the command: first p plot shows and at the end only s-- scatter plot is shown.
I know both the plots are there but could not fix it!!
I really need a help here.
There is small problem in code provided by OP. The wrong dataframe is used in scatter plot.
The correct implementation could be:
#The dataset read is has been modified to read from text as provided in OP
dataset <- read.table(text = "Category Jan Feb
Food 25 100
Makeup 10 150
Travel 200 120
Drinks 164 36", header = TRUE, stringsAsFactors = FALSE)
# mfrow setting will not have any effect on ggplot2 based
par(mfrow=c(2,1))
p<-ggplot(dataset, aes(x=Category, y=Jan)) + geom_bar(stat="identity",)
# OP has used just data for ggplot function to s
s<-ggplot(dataset, aes(x=Category, y=Feb)) + geom_point()
p
s
But the graphs will be drawn in separate pages.
grid.arrange() function gridExtra can be used to draw multiple ggplot based plots in same screen.
You can use multi-graph function and plot any number of graphs on the same page.
Examples below:
http://www.cookbook-r.com/Graphs/Multiple_graphs_on_one_page_(ggplot2)/
Note: it's a custom function, so it's not in any packages. You should just copy and paste, then run it in your console.
This code will create two plots.
a = c(0,1,1,2,2,2,2,2,3,3,3,3,3,3,4,4,4,4,5,5,5,6,6,6,6,6,7,7,7,7,7,7,8,8,8,8,8,8,8,9,9,9)
b = hist(a, freq=FALSE)
dev.new()
plot(b)
The first is a histogram of the density (which I want to have). But if one would like to plot b later on, it will always be plotted as frequency.
Is there any chance to plot the histogram as density past initialisation?
You just need to change the argument in plot
plot(b,freq=FALSE)