student notes / est. for the classroom

HTML, CSS, JavaScript, Python, data science, computer networks — written the way you'd explain it to a classmate, not a compiler.

Top Job & Internship Portals

Handpicked portals for fresher jobs, tech roles, and listings in Hyderabad

GFG

GeeksforGeeks

Tech & Software Roles

Visit →
INT

Internshala

Fresher Jobs & Internships

Visit →
GOOG

Google Careers

Global Google Openings

Visit →
APN

Apna Jobs

Local Jobs in Hyderabad

Visit →
INS

Instahyre

Tech Roles in Hyderabad

Visit →
NAUK

Naukri.com

Fresher Jobs in Hyderabad

Visit →
📢 Updated daily

Internship & Job Alerts

01

Latest notes

February 21, 2024

R programming

 Program 1




# Create the data for the chart
A <- c(17, 32, 8, 53, 1)
 
# Plot the bar chart
barplot(A, horiz = TRUE, xlab = "X-axis",
        ylab = "Y-axis", main ="Horizontal Bar Chart"
       )

How to execute:

Select total program
Right click
Click on Run (or) Ctrl+Enter



program 2


# Create the data for the chart
A <- c(17, 2, 8, 13, 1, 22)
B <- c("Jan", "feb", "Mar", "Apr", "May", "Jun")
 
# Plot the bar chart
barplot(A, names.arg = B, xlab ="Month",
        ylab ="Articles", col ="green",
        main ="GeeksforGeeks-Article chart")



Program 3

# Create the data for the chart A <- c(17, 2, 8, 13, 1, 22) B <- c("Jan", "Feb", "Mar", "Apr", "May", "Jun") # Plot the bar chart with text features barplot(A, names.arg = B, xlab = "Month", ylab = "Articles", col = "steelblue", main = "GeeksforGeeks - Article Chart", cex.main = 1.5, cex.lab = 1.2, cex.axis = 1.1) # Add data labels on top of each bar text( x = barplot(A, names.arg = B, col = "steelblue", ylim = c(0, max(A) * 1.2)), y = A + 1, labels = A, pos = 3, cex = 1.2, col = "black" )



Program 4

colors = c("green", "orange", "brown")
months <- c("Mar", "Apr", "May", "Jun", "Jul")
regions <- c("East", "West", "North")
 
# Create the matrix of the values.
Values <- matrix(c(2, 9, 3, 11, 9, 4, 8, 7, 3, 12, 5, 2, 8, 10, 11),
                nrow = 3, ncol = 5, byrow = TRUE)
 
# Create the bar chart
barplot(Values, main = "Total Revenue", names.arg = months,
                        xlab = "Month", ylab = "Revenue",
                        col = colors, beside = TRUE)
 
# Add the legend to the chart
legend("topleft", regions, cex = 0.7, fill = colors)



Program 5

colors = c("green", "orange", "brown")
months <- c("Mar", "Apr", "May", "Jun", "Jul")
regions <- c("East", "West", "North")
 
# Create the matrix of the values.
Values <- matrix(c(2, 9, 3, 11, 9, 4, 8, 7, 3, 12, 5, 2, 8, 10, 11),
                nrow = 3, ncol = 5, byrow = TRUE)
 
# Create the bar chart
barplot(Values, main = "Total Revenue", names.arg = months,
                        xlab = "Month", ylab = "Revenue",
                        col = colors, beside = TRUE)
 
# Add the legend to the chart
legend("topleft", regions, cex = 0.7, fill = colors)

 

SCAN this QR code to connect with git hub projects


program 6

colors = c("green", "orange", "brown")
months <- c("Mar", "Apr", "May", "Jun", "Jul")
regions <- c("East", "West", "North")
 
# Create the matrix of the values.
Values <- matrix(c(2, 9, 3, 11, 9, 4, 8, 7, 3, 12, 5, 2, 8, 10, 11),
                nrow = 3, ncol = 5, byrow = TRUE)
 
# Create the bar chart
barplot(Values, main = "Total Revenue", names.arg = months,
        xlab = "Month", ylab = "Revenue", col = colors)
 
# Add the legend to the chart
legend("topleft", regions, cex = 0.7, fill = colors)



Program 7

3D Graph

# To illustrate simple right circular cone cone <- function(x, y){ sqrt(x ^ 2 + y ^ 2) } # prepare variables. x <- y <- seq(-1, 1, length = 30) z <- outer(x, y, cone) # plot the 3D surface persp(x, y, z)


program 8

# Adding Titles and Labeling Axes to Plot cone <- function(x, y){ sqrt(x ^ 2 + y ^ 2) } # prepare variables. x <- y <- seq(-1, 1, length = 30) z <- outer(x, y, cone) # plot the 3D surface # Adding Titles and Labeling Axes to Plot persp(x, y, z, main="Perspective Plot of a Cone", zlab = "Height", theta = 30, phi = 15, col = "orange", shade = 0.4)


Program 9

# Visualizing a simple DEM model

z <- 2 * volcano # Exaggerate the relief
x <- 10 * (1:nrow(z)) # 10 meter spacing (S to N)
y <- 10 * (1:ncol(z)) # 10 meter spacing (E to W)


# Don't draw the grid lines : border = NA
par(bg = "gray")
persp(x, y, z, theta = 135, phi = 30, 
col = "brown", scale = FALSE,
ltheta = -120, shade = 0.75, 
border = NA, box = FALSE)


Program 10

# Generate data for the plot
x <- seq(-5, 5, length.out = 50)
y <- seq(-5, 5, length.out = 50)
z <- outer(x, y, function(x, y) sin(sqrt(x^2 + y^2))/sqrt(x^2 + y^2))

# Create the plot
persp(x, y, z, theta = 30, phi = 30, expand = 0.5, col = "lightblue")


Program 11

library(plotly)

df = read.csv('https://raw.githubusercontent.com/plotly/datasets/master/streamtube-wind.csv')

fig <- df %>%
  plot_ly(
    type = 'streamtube',
    x = ~x,
    y = ~y,
    z = ~z,
    u = ~u,
    v = ~v,
    w = ~w,
    starts = list(
      x = rep(80, 16),
      y = rep(c(20,30,40,50), 4),
      z = c(rep(0,4),rep(5,4),rep(10,4),rep(15,4))
    ),
    sizeref = 0.3,
    showscale = F,
    maxdisplayed = 3000
  ) 
fig <- fig %>%
  layout(
    scene = list(
      aspectratio = list(
        x = 2,
        y = 1,
        z = 0.3
      )
    ),
    margin = list(
      t = 20, b = 20, l = 20, r = 20
    )
  )

fig



Program 12


library(plotly) df <- read.csv('https://raw.githubusercontent.com/plotly/datasets/master/clebsch-cubic.csv') fig <- plot_ly( df, type='isosurface', x = ~x, y = ~y, z = ~z, value = ~value, isomin = -10, isomax = 10, surface = list(show = TRUE, count = 4, fill = 0.8, pattern = 'odd'), caps = list( x = list(show = TRUE), y = list(show = TRUE), z = list(show = TRUE) ) ) fig <- fig %>% layout( margin=list(t = 0, l = 0, b = 0), scene=list( camera=list( eye=list( x = 1.86, y = 0.61, z = 0.98 ) ) ) ) fig



Program 13

# Library library(leaflet) # load example data (Fiji Earthquakes) + keep only 100 first lines data(quakes) quakes = head(quakes, 100) # Create a color palette with handmade bins. mybins=seq(4, 6.5, by=0.5) mypalette = colorBin( palette="YlOrBr", domain=quakes$mag, na.color="transparent", bins=mybins) # Final Map leaflet(quakes) %>% addTiles() %>% setView( lat=-27, lng=170 , zoom=4) %>% addProviderTiles("Esri.WorldImagery") %>% addCircleMarkers(~long, ~lat, fillColor = ~mypalette(mag), fillOpacity = 0.7, color="white", radius=8, stroke=FALSE ) %>% addLegend( pal=mypalette, values=~mag, opacity=0.9, title = "Magnitude", position = "bottomright" )




Program 14


# Libraries library(babynames) # Load dataset from github data <- babynames %>% filter(name %in% c("Ashley", "Amanda", "Jessica", "Patricia", "Linda", "Deborah", "Dorothy", "Betty", "Helen")) %>% filter(sex=="F") # line plot = spaghetti chart data %>% ggplot( aes(x=year, y=n, group=name, color=name)) + geom_line() + ggtitle("Popularity of American names in the previous 30 years")




Program 15




1. Data visualization with dataset

# Horizontal Bar Plot for # Ozone concentration in air barplot(airquality$Ozone, main = 'Ozone Concenteration in air', xlab = 'ozone levels', horiz = TRUE)


2. Data visualization with dataset

# Vertical Bar Plot for # Ozone concentration in air barplot(airquality$Ozone, main = 'Ozone Concenteration in air', xlab = 'ozone levels', col ='blue', horiz = FALSE)



3. Data visualization with dataset

# Histogram for Maximum Daily Temperature data(airquality) hist(airquality$Temp, main ="La Guardia Airport's\ Maximum Temperature(Daily)", xlab ="Temperature(Fahrenheit)", xlim = c(50, 125), col ="yellow", freq = TRUE)


4. Data visualization with dataset

# Box plot for average wind speed data(airquality) boxplot(airquality$Wind, main = "Average wind speed\ at La Guardia Airport", xlab = "Miles per hour", ylab = "Wind", col = "orange", border = "brown", horizontal = TRUE, notch = TRUE)


5. Data visualization with dataset

# Multiple Box plots, each representing # an Air Quality Parameter boxplot(airquality[, 0:4], main ='Box Plots for Air Quality Parameters')


6. Data visualization with dataset

# Scatter plot for Ozone Concentration per month data(airquality) plot(airquality$Ozone, airquality$Month, main ="Scatterplot Example", xlab ="Ozone Concentration in parts per billion", ylab =" Month of observation ", pch = 19)



7. Data visualization with dataset

# Set seed for reproducibility # set.seed(110) # Create example data data <- matrix(rnorm(50, 0, 5), nrow = 5, ncol = 5) # Column names colnames(data) <- paste0("col", 1:5) rownames(data) <- paste0("row", 1:5) # Draw a heatmap heatmap(data)


Program 16

# library
library(tidyverse)
 
# Create dataset
data <- data.frame(
  individual=paste( "Mister ", seq(1,60), sep=""),
  value=sample( seq(10,100), 60, replace=T)
)
 
# Set a number of 'empty bar'
empty_bar <- 10
 
# Add lines to the initial dataset
to_add <- matrix(NA, empty_bar, ncol(data))
colnames(to_add) <- colnames(data)
data <- rbind(data, to_add)
data$id <- seq(1, nrow(data))
 
# Get the name and the y position of each label
label_data <- data
number_of_bar <- nrow(label_data)
angle <- 90 - 360 * (label_data$id-0.5) /number_of_bar     # I substract 0.5 because the letter must have the angle of the center of the bars. Not extreme right(1) or extreme left (0)
label_data$hjust <- ifelse( angle < -90, 1, 0)
label_data$angle <- ifelse(angle < -90, angle+180, angle)
 
# Make the plot
p <- ggplot(data, aes(x=as.factor(id), y=value)) +       # Note that id is a factor. If x is numeric, there is some space between the first bar
  geom_bar(stat="identity", fill=alpha("green", 0.3)) +
  ylim(-100,120) +
  theme_minimal() +
  theme(
    axis.text = element_blank(),
    axis.title = element_blank(),
    panel.grid = element_blank(),
    plot.margin = unit(rep(-1,4), "cm") 
  ) +
  coord_polar(start = 0) + 
  geom_text(data=label_data, aes(x=id, y=value+10, label=individual, hjust=hjust), color="black", fontface="bold",alpha=0.6, size=2.5, angle= label_data$angle, inherit.aes = FALSE ) 
 
p



Program 17




Program 18

# Libraries library(tidyverse) library(hrbrthemes) library(babynames) library(viridis) # Load dataset from github data <- read.table("https://raw.githubusercontent.com/holtzy/data_to_viz/master/Example_dataset/3_TwoNumOrdered.csv", header=T) data$date <- as.Date(data$date) # Load dataset from github don <- babynames %>% filter(name %in% c("Ashley", "Amanda", "Mary", "Deborah", "Dorothy", "Betty", "Helen", "Jennifer", "Shirley")) %>% filter(sex=="F") # Plot don %>% ggplot( aes(x=year, y=n, group=name, fill=name)) + geom_area() + scale_fill_viridis(discrete = TRUE) + theme(legend.position="none") + ggtitle("Popularity of American names in the previous 30 years") + theme_ipsum() + theme( legend.position="none", panel.spacing = unit(0, "lines"), strip.text.x = element_text(size = 8), plot.title = element_text(size=13) ) + facet_wrap(~name, scale="free_y")


program 19 (Animation)

# Get data: library(gapminder) # Charge libraries: library(ggplot2) library(gganimate) # Make a ggplot, but add frame=year: one image per year ggplot(gapminder, aes(gdpPercap, lifeExp, size = pop, color = continent)) + geom_point() + scale_x_log10() + theme_bw() + # gganimate specific bits: labs(title = 'Year: {frame_time}', x = 'GDP per capita', y = 'life expectancy') + transition_time(year) + ease_aes('linear') # Save at gif: anim_save("271-ggplot2-animated-gif-chart-with-gganimate1.gif")



Program 20

# libraries: library(ggplot2) library(gganimate) # Make 2 basic states and concatenate them: a <- data.frame(group=c("A","B","C"), values=c(3,2,4), frame=rep('a',3)) b <- data.frame(group=c("A","B","C"), values=c(5,3,7), frame=rep('b',3)) data <- rbind(a,b) # Basic barplot: ggplot(a, aes(x=group, y=values, fill=group)) + geom_bar(stat='identity') # Make a ggplot, but add frame=year: one image per year ggplot(data, aes(x=group, y=values, fill=group)) + geom_bar(stat='identity') + theme_bw() + # gganimate specific bits: transition_states( frame, transition_length = 2, state_length = 1 ) + ease_aes('sine-in-out') # Save at gif: anim_save("288-animated-barplot-transition.gif")



Program 21


1. Barplot

# Horizontal Bar Plot for # Ozone concentration in air barplot(weatherHistory$Humidity, main = 'Humidity in air', xlab = 'Humidity levels', horiz = TRUE)



2. Histogram

# Horizontal Bar Plot for 
# Ozone concentration in air 
hist(weatherHistory$Humidity, 
        main = 'Humidity Concenteration in air', 
        xlab = 'Humidity levels', horiz = TRUE) 


3. Box plot

# Box plot for average wind speed 
data(weatherHistory) 

boxplot(weatherHistory$`Temperature (C)`, main = "Average Temp", 
        xlab = "in a day", ylab = "windspeed", 
        col = "orange", border = "brown", 
        horizontal = TRUE, notch = TRUE) 

4. Plot

# Scatter plot for Ozone Concentration per month 
data(weatherHistory) 

plot(weatherHistory$`Wind Speed (km/h)`, weatherHistory$`Wind Bearing (degrees)`, 
     main ="Scatterplot Example", 
     xlab ="Ozone Concentration in parts per billion", 
     ylab =" Month of observation ", pch = 19) 



Program 22

# Install package if not installed
if (!require(plotly)) {
  install.packages("plotly")
  library(plotly)
} else {
  library(plotly)
}

#############################
# 1️⃣ 3D SCATTER PLOT
#############################

# Generate sample data
set.seed(123)
df <- data.frame(
  x = rnorm(200),
  y = rnorm(200)
)

df$z <- df$x^2 + df$y^2

# Create interactive 3D scatter plot
scatter_plot <- plot_ly(
  df,
  x = ~x,
  y = ~y,
  z = ~z,
  type = "scatter3d",
  mode = "markers",
  marker = list(
    size = 4,
    color = ~z,
    colorscale = "Viridis"
  )
) %>%
  layout(title = "3D Scatter Plot")

scatter_plot


#############################
# 2️⃣ 3D SURFACE PLOT
#############################

# Create grid data
x <- seq(-10, 10, length.out = 50)
y <- seq(-10, 10, length.out = 50)

z <- outer(x, y, function(x, y) {
  sin(sqrt(x^2 + y^2))
})

# Create interactive 3D surface plot
surface_plot <- plot_ly(
  x = x,
  y = y,
  z = z,
  type = "surface"
) %>%
  layout(title = "3D Surface Plot")

surface_plot








1 comment:

02

Capstone resource hub

Codingacharya

Capstone Learning Resources, Notes & Project Hub

TCS NQT Questions
Read Notes
Machine Learning – ACE Theory
Read Notes
Machine Learning PPT
Read Notes
MachienLearning LAB
Read Notes
CSPT LAB programs
Read Notes
Time table and CSPT syllabus
Read Notes
Appreciations
Read Notes
ISTE life memberships
Read Notes
Artificial Intelligence & Analytics
Read Notes
Fullstack Web Dev
Read Notes
MERN Web Dev
Read Notes
Course Structure
Read Notes
Cloud Computing
Read Notes
90 Days ML Challenge
Read Notes
Advanced Analytics & Viz
Read Notes
Advanced Machine Learning
Read Notes
React JS
Read Notes
ML Chaitanya
Read Notes
Important Links
Read Notes
CSS Effects
Read Notes
RESUME
Read Notes
Bootstrap CSS
Read Notes
MongoDB
Read Notes
OWN Python Package
Read Notes
HTML Course
Read Notes
HTML Projects
Read Notes
GitHub Projects
Read Notes
Angular JS
Read Notes
Journals
Read Notes
NLP Notes
Read Notes
Videos
Read Notes
Data Analytics & Viz
Read Notes
Cloud Computing (Archive)
Read Notes
Open CV
Read Notes
jQuery
Read Notes
React JS (Archive)
Read Notes
Node JS
Read Notes
DAV Theory
Read Notes
DAV Lab
Read Notes
Big Data Notes
Read Notes
R-Programming
Read Notes
HADOOP Lab
Read Notes
GATE DA
Read Notes
JAVA Lab
Read Notes
Computer Networks
Read Notes
03

Live projects & profiles