Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To create a scatterplot using R's ggplot with each point occupying a square unit, regardless of the screen size you can use the following code:

library(ggplot2)

# create some sample data
x <- rnorm(100)
y <- rnorm(100)

# create a dataframe
data <- data.frame(x, y)

# create the plot
ggplot(data, aes(x = x, y = y)) +
  geom_point(shape = 15, size = 10)

The size parameter in geom_point() controls the size of the points on the plot. By default, this is specified in terms of millimeters, so the size of the points will vary depending on the screen size. However, you can specify the size of the points in terms of a fixed number of screen units using the unit() function from the grid package. For example, to specify that each point should occupy a square unit of screen space, regardless of the screen size, you can change the size parameter to unit(1, "cm"):

ggplot(data, aes(x = x, y = y)) +
  geom_point(shape = 15, size = unit(1, "cm"))

This will ensure that each point occupies a square of 1 cm x 1 cm on the screen. You can adjust the size of the squares by changing the size argument in the unit() function.