gravatar

Pranav_Anand

Pranav Anand

Recently Published

Map
library(maps) library(ggmap) data("USArrests") us_map <- map_data("state") USArrests$region <- tolower(rownames(USArrests)) map_data <- merge(us_map, USArrests, by = "region") map_plot <- ggplot(map_data, aes(x = long, y = lat, group = group, fill = Murder)) + geom_polygon(color = "black") + scale_fill_gradient(low = "white", high = "red") + labs(title = "Map: Murder Rate by State", fill = "Murder Rate") + theme_void() print(map_plot)
Box Plot
box_plot <- ggplot(diamonds, aes(x = cut, y = price, fill = cut)) + geom_boxplot() + labs(title = "Box Plot: Price Distribution by Cut", x = "Cut", y = "Price") + theme_minimal() print(box_plot)
Waffle chart
library(wordcloud) library(fmsb) library(waffle) library(reshape2) color_counts <- diamonds %>% group_by(color) %>% summarise(count = n()) waffle_chart <- waffle(color_counts$count, rows = 5, title = "Waffle Chart: Proportion of Diamonds by Color") print(waffle_chart)
Word Cloud
library(wordcloud) library(fmsb) library(waffle) library(reshape2) wordcloud(words = unique(diamonds$clarity), freq = table(diamonds$clarity), colors = brewer.pal(8, "Dark2"), main = "Word Cloud: Diamond Clarity")
Line Plot
line_plot <- ggplot(diamonds, aes(x = carat, y = price)) + geom_point(alpha = 0.3) + geom_smooth(method = "lm", color = "red") + labs(title = "Line Plot with Regression: Price Trends Over Carat", x = "Carat", y = "Price") + theme_minimal() print(line_plot)
Scatter Plot
library(ggplot2) library(dplyr) scatter_plot <- ggplot(diamonds, aes(x = carat, y = price, color = cut)) + geom_point(alpha = 0.5) + labs(title = "Scatter Plot: Carat vs Price", x = "Carat", y = "Price") + theme_minimal() print(scatter_plot)
Pie chart
library(ggplot2) library(dplyr) clarity_counts <- diamonds %>% group_by(clarity) %>% summarise(count = n()) %>% mutate(percentage = count / sum(count) * 100) pie_chart <- ggplot(clarity_counts, aes(x = "", y = percentage, fill = clarity)) + geom_bar(stat = "identity", width = 1) + coord_polar("y") + labs(title = "Pie Chart: Proportion of Diamonds by Clarity") + theme_void() print(pie_chart)
Histogram
library(ggplot2) histogram <- ggplot(diamonds, aes(x = price)) + geom_histogram(binwidth = 500, fill = "blue", color = "black") + labs(title = "Histogram: Distribution of Diamond Prices", x = "Price", y = "Frequency") + theme_minimal() print(histogram)
Bar Plot
library(ggplot2) data("diamonds") bar_chart <- ggplot(diamonds, aes(x = cut, fill = cut)) + geom_bar() + labs(title = "Bar Chart: Count of Diamonds by Cut", x = "Cut", y = "Count") + theme_minimal() print(bar_chart)