Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make lattice xyplot() grayscale in R?

Tags:

r

lattice

What is the simplest way to make just this plot grayscale (or perhaps black and white) rather than the default multi-colour:

xyplot(y1 + y2 ~ x, mydata, auto.key=TRUE)

I've seen discussion of creating new graphics devices or changing options for all plots, but is there an option that I can include perhaps in the xyplot() function itself that will convert the plot to grayscale?

like image 375
Jeromy Anglim Avatar asked Feb 16 '12 06:02

Jeromy Anglim


People also ask

How to create a scatter plot in R using lattice?

The xyplot () function can be used to create a scatter plot in R using the lattice package. The iris dataset is perfectly suited for this example. We can color the points of the scatter plot based on the categories. We can change the x and y labels and also add smoothing lines to the plot using the arguments in the xyplot () function.

How to create strip plots and density plots in R?

Strip plots can be created in R using the stripplot () function of the lattice package. We will be using the same ToothGrowth dataset. 6. Density Plots in the Lattice Package We can create density plots in R using the densityplot () function of the lattice package.

What is lattice package in R?

The main focus of the package is multivariate data. It has a wide variety of functions that enable it to create basic plots of the base R package as well as enhance on them. Let us start looking at all the functions and graphs in the lattice package, one-by-one.

How to draw a ggplot2 scatterplot in R?

Now, we can use the ggplot and geom_point functions to draw a ggplot2 scatterplot in R: Figure 9: Scatterplot Created with the ggplot2 Package. Figure 9 contains the same XYplot as already shown in Example 1. This time, however, the scatterplot is visualized in the typical ggplot2 style.


1 Answers

library(lattice)
bwtheme <- standard.theme("pdf", color=FALSE)
mydata <- data.frame(y1=rnorm(10), y2=rnorm(10), x=1:10)
xyplot(y1 + y2 ~ x, mydata, auto.key=TRUE, par.settings=bwtheme)

For comparison:

comparison of color vs black/white

like image 158
Aaron left Stack Overflow Avatar answered Oct 26 '22 04:10

Aaron left Stack Overflow