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.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2022-01-08 11:00:00 +0000
Seen: 14 times
Last updated: Oct 24 '21
What is the method of inserting y-axis labels into a coord_polar chart in ggplot?
Why is ggplot displaying decimal values in the legend when the column contains numerical values?
What is the method for merging two plots in R studio with ggplot?
In ggplot, certain bin intervals in the legend are lacking color.
What is the method to adjust Unity point light --> near plane to a value smaller than 0.1?
At what point the conditions for Jquery If, else if, else statements are not being executed?