I want to be able to show three different density curves on the same axis. I've got the code below so far but i don't know how to combine them to so that they can
curve(dnorm(x,mean=0,sd=1),col="darkgreen",xlim=c(-4,8),ylim=c(0,.8))
curve(dnorm(x,mean = 0,sd=1.5),col="red",xlim = c(-5,8),ylim=c(0,.6))
curve(dnorm(x,mean = 0.5,sd=0.5),col="black",xlim = c(-2,8), ylim =c(0,1))
This is the basic solution. You can add more formatting if need be (for axes etc). Note you need to change the xlim and ylim to match on the plots.
curve(dnorm(x,mean=0,sd=1),col="darkgreen",xlim=c(-5,8),ylim=c(0,1), ylab = "")
par(new = TRUE)
curve(dnorm(x,mean = 0,sd=1.5),col="red",xlim = c(-5,8),ylim=c(0,1), ylab = "")
par(new = TRUE)
curve(dnorm(x,mean = 0.5,sd=0.5),col="black",xlim = c(-5,8), ylim =c(0,1), ylab = "")
Related
library(tseries)
library(readxl)
data = read_excel(.......)
#Create tseries
equity = ts(data$EQUITY, start = c(2015,01,01), end = c(2020,01,01), frequency = 12)
cci = ts(data$CCI, start = c(2015,01,01), end = c(2020,01,01), frequency = 12)
#Plot the two series together
ts.plot(equity, cci, lty = c(1:2))
This code returns the following chart: R Chart.
Keeping in mind that I'd like to use the ts.plot function since I'm plotting other tseries objects and I'm not a fan of how ggplot2 handles them, is there a way to add a second axis to the chart and make it so that the two series appear superimposed instead of being far apart like in the linked image? The desired result would be like in this chart plotted with Python and matplotlib: Python Chart, possibly with a legend, too.
Any help would be greatly appreciated, thanks!
Use plot.ts rather than ts.plot like this. (See ?legend for other legend position keywords.)
z <- ts(cbind(1:10, 110:101))
col <- c("black", "blue")
plot(z[, 1], xlab = "", ylab = "", yaxt = "n", col = col[1])
axis(2, col.axis = col[1])
par(new = TRUE)
plot(z[, 2], xlab = "", ylab = "", yaxt = "n", col = col[2])
axis(4, col.axis = col[2])
legend("top", legend = c("z1", "z2"), lty = 1,
col = col, text.col = col)
Hi I am trying to change the scale on the x-axis to a log scale on a plot generated by
model2 <- nlme(consumption~Q*10^(5*(exp(-alpha*Q*price)-1)), fixed=Q+alpha~1,`random=Q+alpha~1|ratid, groups = ~ treatment,`data = oxydata, start = c(Q=3, alpha=0.001))
plot(augPred(model2), log='x', xlim = c(1,3000), xlab = "Price (resp/mg", ylab = "Consumption")
However, the log='x' or log="x" does nothing to change the x-axis scale. I can change the xlim and ylim, add titles etc. but I can't seem to change the x-axis to a log scale. Any help or verification that it can or can't be done is greatly appreciated.
Ugly plot with data all crammed
Thanks to anyone that was trying to figure this out, but I got it. This function uses the xyplot(), which requires the scale = list...
`plot(augPred(model2), scale = list(x = list(log = 10)), xlim = c(1,3000), xlab = "Price (resp/mg", ylab = "Consumption")
I have built two graphs in one (two different y axis but plotting on the same graph). I want to show the connection between the values on the left and the values on the right (Do they stay consistently > 0 or <0 or change?)
Now what I need is to link the two sides of the graph with a line to see if it decreases/increases. So I want a corresponding dot on the left to be linked to the corresponding dot on the right by a line.
But because the y axis values on the left and the right are different, I am not figuring out how this can work.
Here is my code to build the graph:
## Plot first set of data and draw its axis
plot(rep(1, length(DEG)), DEG, xlim = c(0,4), xaxt = "n",
ylim = c(-5, 5), col = "black", xlab = "", ylab = "")
axis(1, at = c(1))
## Allow a second plot on the same graph
par(new = TRUE)
## Plot the second plot and put axis scale on right
plot(rep(3, length(DMG)), DMG, axes = F, xlim = c(0, 4), xaxt = "n",
ylim = c(-80, 80), col = "black", xlab = "", ylab = "")
axis(1, at = c(3)))
axis(side = 4)
abline(h = 0, col = "red")
Does anyone have an idea? I tried the basic line:
lines(x$DEG[x$Genes == "FEX_0000936"], x$DMG[x$Genes == "FEX_0000936"],
type="o", pch=22, col="seagreen3")
Here is my graph perhaps it is clearer when seeing it:
Thanks for your help.
I'm using the pca3d package to plot principle components 1-5 of gene expression data. I was having a hard time standardizing the 3d plot, so instead I plotted PC1 vs PC2, PC2 vs PC3, etc. My code for that is below
par(mfrow = c(2,2))
for(n in 1:4){
pca2d(pcaSix$x[,n:(n+1)], # Mclust Grouping - module Genes
title = "Six Genes From Abel, et al. 2011",
shape = 16,
group = clustersMod1six,
radius = 1,
legend = NULL,
show.centroids = FALSE,
show.ellipses = TRUE,
col = ClusterColorsSix,
axe.titles = c(paste("PCA",
n,
sep = ""),
paste("PCA",
n+1,
sep = "")
),
xlim = c(-1,1),
ylim = c(-1,1)
)
}
The issue that I'm having is that the xlim and ylim arguments do not appear to have any effect on the plot, I found this post that suggested using the asp argument, but setting asp did not allow me to change the axes.
Does anyone know how I could force pca2d to change the axes limits?
Without modifying the function, there is no way to control the axes. See line 32:
plot(NULL, type= "n",
xlim= prange$x,
ylim= prange$y,
xlab= xlab,
ylab= ylab,
bty= "none"
)
My question is similar to this:
Plotting bar plot below xyplot with same x-axis?, but for the lattice package rather than ggplot.
I have 21 xyplots, all with the same x-axis scale, but different y-axis scales. I would like to plot all 21 lines with only 1 x-axis, but 21 different y-axes scales (one row per line). I nearly have it here:, but the redundant x-axes printed to each panel make this figure ridiculous. My script:
xyplot(numhr~year | spp, xlab = "Time(years)",
ylab = "Abundance (# per party hr)", type = "l", aspect = "fill",
strip = FALSE, scales = list(relation = "free"), as.table = TRUE,
layout = c(1,21), xlim = c(1940,2010))
Any help?
~Kevin
As per the comment above, the necessary change to my code to make this work involves adding 'y = list(relation = "free")' to the 'scales' component. Edited code below:
xyplot(numhr~year | spp, xlab = "Time(years)",
ylab = "Abundance (# per party hr)", type = "l", aspect = "fill",
strip = FALSE, scales = list(y = list(relation = "free")), as.table = TRUE,
layout = c(1,21), xlim = c(1940,2010))
Which produces this (unfortunately the y-axes are still too condensed, but this does address the question originally posed):