I have a dataset with 14 variables, all numerical but with very different scales. My first attempt at a boxplot was not very representative:
> boxplot(dd$crim, dd$zn, dd$indus, dd$chas, dd$nox, dd$rm, dd$age, dd$dis, dd$rad, dd$tax, dd$ptratio, dd$bb, dd$lstat, dd$medv)
So now I'm looking to create multiple individual box plots, side by side such that each plot has a suitable scale and is more readable and presentable. Is this possible?
Related
I'm very new to R and to survival analyses. I'm trying to plot survival curves for each level of a categorical IV. Importantly, I want them plotted on separate plots. Is there an easy way to do this? An obvious solution is to just create separate data frames for the categories, however, that seems rather cumbersome.
my code:
figure_site <- survfit(survObject~site, data = uis_data)
plot(figure_site)
site has 2 levels (0, 1) and I want two plots - one for site==0 and site==1.
Thanks!
Sorry for basic question, I am new to R.
I would like to plot a box with subcategories and then with measurements taken over time.
For example I have tried this:
boxplot(field_data$week_1~field_data$field, ylab= 'number of infected plants')
This gives me two box plots (field is either ‘north’ or ‘south’). I want to split each boxplot into two boxplots by "position" variable (1 or 2). Is there a way to make it so that I will still have a plot with 2 main categories defined by "field", but then each will consist of two boxplots defined by "position" variable. I would also then like to plot the results from the ‘week_2’ readings next to the 'week_1' set of box plots. All of the data is in one df. I have other variables ('beds' and 'rows') with different levels too that categorise the measurements taken.
I have tried with ggplot but not sure how to do this or if this is the right function.
Thank you.
Using the lattice package in R, I would like to plot one row of 7 diagrams, all using the same Y-axis. The diagrams should be (vertical) line diagrams. The problem is that my data are each in 7 separate dataframes (containing X and Y data), with different slightly different limits on the Y-axis data.
Besides all tutorials, I don't get it right. What must my Code look like? Is there even a clean solution for this in lattice?
You could combine all your data frames into one and then do something like
xyplot(Y~X|odf,data=combinedDF,layout=c(7,1))
where odf is an indicator column of the original data frame. This by default should use a common y scale.
Apart from combining the data, you could create 7 separate plots, then print them.
p1 <- xyplot(Y~X,data=DF1,ylim=c(Y1,Y2))
p2 <- xyplot(Y~X,data=DF2,ylim=c(Y1,Y2))
etc.
To print:
print(p1,split=c(1,1,7,1),more=TRUE)
print(p2,split=c(2,1,7,1),more=TRUE)
...
print(p7,split=c(7,1,7,1),more=FALSE)
see ?print.trellis.
Of course, arranging single plots like this doesn't really use the features of lattice. You could just as easily do this with base graphics using layout or par(mfrow=c(1,7)) for example, and a common ylim.
I have 2 separate histogram clustered plots whose x-axis is the same and the bars are also same, but y-axis is different.
I want to represent the combined information from these 2 plots in a single plot. One way to do this is to assign the y-axis of the second plot as z-axis. I have attached a rough example here:
Questions:
Is there a simple way to do this in gnuplot?
Are there better ways of combining such information from two plots together?
Sorry for the newbie R question...
I have a data.frame that contains measurements of a single variable. These measurements will be distributed differently depending on whether the thing being measured is of type A or type B; that is, you can imagine that my column names are: measurement, type label (A or B). I want to plot the histograms of the measurements for A and B separately, and put the two histograms in the same plot, with each histogram normalised to unit area (this is because I expect the proportions of A and B to differ significantly). By unit area, I mean that A and B each have unit area, not that A+B have unit area. Basically, I want something like geom_density, but I don't want a smoothed distributions for each; I want the histogram bars. Not interleaved, but plotted one on top of the other. Not stacked, although it would be interesting to know how to do this also. (The purpose of this plot is to explore differences in the shapes of the distributions that would indicate that there are quantitative differences between A and B that could be used to distinguish between them.) That's all. Two or more histograms -- not smoothed density plots -- in the same plot with each normalised to unit area. Thanks!
Something like this?
# generate example
set.seed(1)
df <- data.frame(Type=c(rep("A",1000),rep("B",4000)),
Value=c(rnorm(1000,mean=25,sd=10),rchisq(4000,15)))
# you start here...
library(ggplot2)
ggplot(df, aes(x=Value))+
geom_histogram(aes(y=..density..,fill=Type),color="grey80")+
facet_grid(Type~.)
Note that there are 4 times as many samples of type B.
You can also set the y-axis scales to float using: scales="free_y" in the call to facet_grid(...).