Displaying 20 results from an estimated 2000 matches similar to: "Density plot in ggplot2"
2008 Jul 24
1
ggplot question
I am trying to do something simple with ggplot. I wish to draw a density
plot split by group, and fill each group with a different colour (and
each with an alpha =0.25). I have tried a number of variations of the
following, but cannot find a way to define the colour of the fill, its
transparency and the line around it individually - something in the
syntax continues to defy me.
2017 Oct 12
2
dual y-axis for ggplot
Hi,
To my knowledge, an excellent of ggplot with a second y-axis is
https://rpubs.com/MarkusLoew/226759
In this example, the author uses two colors for the two lines, but the
line shapes are the same -- both are solid. Could each line have its own
color as well as its own shape? For example, can I make the red line with
the linetype "twodash", while the blue line with the
2013 Mar 25
2
Plot Matrix with Data
Hi ,
I would like to use ggplot2 to plot a matrix as an image.
You can copy paste the following
Data<-matrix(data=rnorm(900,80,20),nrow=30,ncol=30)
lengthOut<-5
Lengths<- 15
library(reshape2)
library(ggplot2)
tdm <- melt(Data)
ggplot(tdm, aes(x = Var2, y = Var1, fill = factor(value)),levels=seq(0,1,by=0.1)) +
labs(x = "MHz", y =
2017 Oct 12
1
dual y-axis for ggplot
Hi John,
You can try the following:
override.linetype=c("twodash","solid")
p <- ggplot(obs, aes(x = Timestamp))
p <- p + geom_line(aes(y = air_temp, colour = "Temperature", linetype
="Temperature"))
p <- p + geom_line(aes(y = rel_hum/5, colour = "Humidity",
linetype="Humidity"))
p <- p +
2009 Mar 25
2
[ggplot2] Densityplot, grouping and NAs
Dear all,
I do not fully understand how ggplot2 handles NAs. See the following
example:
library(ggplot2)
x <- rnorm(150)
g <- as.factor(c(rep(c(0,1,NA),50)))
mydf <- data.frame(x,g)
m <- ggplot(aes(x = x, group = g, color = g), data = mydf)
m + geom_density()
How do I get rid of the NAs (i.e. the blue colored curve)?
I thought
## m <- ggplot(aes(x = x, group = g, color = g,
2017 Oct 12
0
dual y-axis for ggplot
Sorry let me clarify.
If I modify the line
p <- p + geom_line(aes(y = air_temp, colour = "Temperature"))
by
p <- p + geom_line(aes(y = air_temp, colour = "Temperature", linetype
="Temperature"))
and
p <- p + geom_line(aes(y = rel_hum/5, colour = "Humidity"))
by
p <- p + geom_line(aes(y = rel_hum/5, colour = "Humidity",
2013 Feb 25
1
ggplot2 Increase font size
Dear all,
I am using the code as below
tdm <- melt(matrixToPlot)
p<- ggplot(tdm, aes(x = Var2, y = Var1, fill = factor(value))) +
labs(x = "Mz", y = "T", fill = "D") +
geom_raster(alpha=1) +
scale_fill_discrete(h.start=1) +
scale_x_continuous(expand = c(0, 0)) +
2009 Jan 30
1
Using ggplot2 I need to move the location of legend to on the plot
Thanks again for the hints about adding the vertical line to the hist plot and in ggplot. That worked great.
Based on that advice I've been flipping through the ggplot2 doc and ggplot-static\index.html webpage more looking for the answer to the next question.
Unfortunately, I haven't stumbled on a description of how to move around the location of the legend.
Here is what I
2012 Nov 07
1
change colour of geom_step by scale_colour_manual
Hi,
Color of my step plot is now by default. Now I'd like to change the color as
the grey scale I specified. I don't know why I got three black plot. Here I
attach two version of codes. The first one produces a step plot with color
by default. The second one, modified from the first one, is not producing
the grey scale I want. Any help would be highly appreciated.
[version 1- working]
2011 Jun 07
1
ggplot2 Histogram with density curve
I am learning ggplot2 commands and I have figured out how to create
histograms and density curves but I am not sure how to add a density curve
on top of a histogram.
Here are the two graphs that I created.
## Histogram
t<-rnorm(500)
w<-qplot(t, main="Normal Random Sample", fill=I("blue"), colour=I("black"),
geom="histogram")
w
##Density Curve
2009 Jan 29
2
Adding vertical line to histogram and qplot "stacked" plot
R-users it appears I am leaning on your knowledge once again. Is there any way to add a vertical line to a histogram and qplot "stacked" plot? Here is my current attempt:
"qplot" approach attempt:
qplot(Run, data = data_dataframe, breaks = breaks, fill = Temperature, main = short_title) + scale_x_continuous("Data") + scale_y_continuous("Freq")
2011 Jul 06
2
how to best present concentrated data points/ ggplot2
Hi all,
I am trying to plot a weighted density plot for two different types and want to show the data points on the x axis.
The code is as follows. The data points are very concentrated. Is there a better way to present it( should I set the alpha value or something else)?
Thanks!
YL
library(ggplot2)
x <- rnorm(10000)
a <- rnorm(5000)
b <- rnorm(5000)
weights.x <- abs(a/sum(a))
2007 Nov 08
1
ggplot2 facets as rows and columns
Does anyone (Hadley??) know if there's a straightforward
way in ggplot2 to get data divided by a single factor to
plot as a rectangular grid of subplots? So far I've only
been able to get such data plotted as a single row or
single column of skinny subplots. The code below gives
an example implemented with lattice, and my best
attempt in ggplot2
cheers
Ben Bolker
------------
g=
2008 Mar 04
1
ggplot2 - Problem with grid plot
Hi R-help
I'm trying to create a grid plot in which each plot in the grid contains two
density plots (colored by factor) and two vertical lines at the respective
medians (also colored by the factor).
Using the diamonds dataset as an example, the following commands give me
price density plots by factor cut in a single, ungridded plot.
p <- ggplot(data=diamonds, aes(x=price)) +
2009 Aug 20
1
ggsave to .png bug in ggplot2 (?)
Text is really small and legend boxes are huge in this plot when saved to
.png with ggsave. Plot is correct (i.e. looks the same as the screen) when
saved with dev.print. Saving to .pdf with ggsave give the correct output.
I'm a noob at ggplot2 so this may be user error rather than a bug. However
the interface to ggsave seems simple enough to exclude many possibilities
for screwing this up
2009 Jan 28
1
Changing histogram stack in qplot
I've been using qplot pretty successfully to generate stacked histograms. However, it appears that I need to tweak the colors a little.
I've got three temperature variables (characters not numeric) and I need to change from the default qplot colors to the following:
Low = Blue
Middle = black
High = Red
Here is pseudo code of what I have currently:qplot(Run, data = TestData, breaks =
2008 Apr 04
0
ggplot2 - version 0.6
ggplot2 ------------------------------------------------------------
ggplot2 is a plotting system for R, based on the grammar of graphics,
which tries to take the good parts of base and lattice graphics and
avoid bad parts. It takes care of many of the fiddly details
that make plotting a hassle (like drawing legends) as well as
providing a powerful model of graphics that makes it easy to produce
2008 Apr 04
0
ggplot2 - version 0.6
ggplot2 ------------------------------------------------------------
ggplot2 is a plotting system for R, based on the grammar of graphics,
which tries to take the good parts of base and lattice graphics and
avoid bad parts. It takes care of many of the fiddly details
that make plotting a hassle (like drawing legends) as well as
providing a powerful model of graphics that makes it easy to produce
2010 Nov 23
1
specifying colours in a ggplot2 piechart
Someone was asking how to do a 16 category piechart in OpenOffice Calc and it appears that it can not be done (which we, probably, should be happy about) but I thought that I'd try it in ggplot2.
It works but I then thought I'd like to make the colours more distinctive but fro some reason I don't seem to be able to use manually assigned colours.
Can anyone suggest where I'm
2010 Mar 24
1
GGPLOT2: Reverse order of legend to match order of x-axis
How do I reverse the order of the legend in a bar plot to match order of the
x-axis? In other words, I want the stacked colors of the legend to match the
stacked colors of the bar plot. I tried this, but it didn't work.
colors <- c("5" = "red","4" = "blue","3" = "darkgreen")
p <- qplot(factor(cyl), data=mtcars,