make apretty histogram in r

Here is an example of how to create a histogram using ggplot2 in R:

main.r
library(ggplot2)

# Create example data
data <- data.frame(values = rnorm(1000))

# Plot histogram
ggplot(data, aes(x = values)) +
  geom_histogram(fill = "lightblue", color = "black") +
  labs(title = "Histogram of Random Data", x = "Values", y = "Frequency")
261 chars
10 lines

In this example, we are using the ggplot2 library to create the histogram. We first create an example dataset with 1000 random values using R's rnorm function.

Next, we use the ggplot function to create the plot and specify the values column in the dataset as the x-axis variable. We add a geom_histogram layer to create the histogram with a light blue fill color and black outline. Finally, we add a title and axis labels using the labs function.

This produces a simple and visually appealing histogram that is easy to interpret.

gistlibby LogSnag