2023년 1월 21일 토요일

More examples in how to create a basic pie chart in R

 an example of creating a basic pie chart in R using the ggplot2 library:

library(ggplot2) 
 # Create some data 
data <- data.frame( category = c("A", "B", "C"), value = c(10, 20, 30) ) 
# Create the pie chart 
ggplot(data, aes(x = "", y = value, fill = category)) + geom_bar(width = 1, stat = "identity") + coord_polar("y", start = 0) + theme_void()

This will create a pie chart with 3 slices, labeled "A", "B", and "C", and with the corresponding values of 10, 20, and 30.

Another way to create a basic pie chart in R is by using the plotly library.

library(plotly) 
data <- data.frame( category = c("A", "B", "C"), value = c(10, 20, 30) ) 
plot_ly(data, labels = ~category, values = ~value, type = 'pie')

This will create a interactive pie chart with 3 slices, labeled "A", "B", and "C", and with the corresponding values of 10, 20, and 30.


댓글 없음:

댓글 쓰기