R
@Rushali_07
P 7 last question
##Boxplot using notch Program:
# Plot the chart.
boxplot(mpg ~ cyl, data = mtcars,
xlab = "Number of Cylinders", ylab = "Miles Per Gallon",
main = "Mileage Data",
notch = TRUE,
varwidth = TRUE,
col = c("green", "red", "blue"), names = c("High", "Medium", "Low"))
P 7 last question
##Pie charts Program:
data("chickwts")
# main is used to create
# an heading for the chart
d = table(chickwts$feed)
pie(d[order(d, decreasing=TRUE)], clockwise=TRUE, main="Pie Chart of feeds from chichwits", )
data(chickwts)
P No 8
library (ggplot2)
##Polar Plot
#mtcars %>%
#dplyr::group_by(cyl) %>%
#dplyr::summarize(mpg = median(mpg)) %>%
#ggplot(aes(x = cyl, y = mpg)) + geom_col(aes(fill =cyl), color = NA) + labs(x = "", y = "Median mpg") + coord_polar()
##Bump Chart
ggplot(mtcars, aes(x = hp, y = mpg, group = cyl))+ geom_line(aes(color = cyl), size = 2) + geom_point(aes(color = cyl), size = 4) + scale_y_reverse(breaks = 1:nrow(mtcars))
##Pairplot with ggpairs
#library(GGally)
P No 8
library (ggplot2)
##Scatter Plot
data(iris)
ggplot(iris, aes(x=Sepal.Length, y=Petal.Length))+geom_point()
##geometry of data
ggplot(iris, aes(x=Sepal.Length, y=Petal.Length, col=Species, shape=Species))+geom_point()
## smooth line
ggplot(iris, aes(x=Sepal.Length, y=Petal.Length, col=Species))+geom_point() +geom_smooth()
ggplot(iris, aes(x=Sepal.Length, y=Petal.Length, col=Species))+geom_point(color = "blue") + geom_smooth(color = "red")
data(mtcars)
practical no 7
#Slice Percentage & Chart Legend Program:
# Create data for the graph.
geeks <- c(23, 56, 20, 63)
labels <- c("Mumbai", "Pune", "Chennai", "Bangalore")
piepercent<- round(100 * geeks / sum(geeks), 1)
# Plot the chart.
pie(geeks, labels = piepercent,
main = "City pie chart", col = rainbow(length(geeks)))
legend("topright", c("Mumbai", "Pune", "Chennai", "Bangalore"),
cex = 0.5, fill = rainbow(length(geeks)))
practical no 7
#Create the data for the chart.
v <- c(17, 25, 38, 13, 41)
t <- c(22, 19, 36, 19, 23)
m <- c(25, 14, 16, 34, 29)
# Plot the bar chart.
plot(v, type = "o", col = "red",
xlab = "Month", ylab = "Article Written ",
main = "Article Written chart")
lines(t, type = "o", col = "blue")
lines(m, type = "o", col = "green")
practical no 7
##Horizontal Bar Plot for
##Ozone concentration in air
barplot(airquality$Ozone,
main = 'Ozone Concenteration in air',
xlab = 'ozone levels', horiz = TRUE)
# Vertical Bar Plot for
# Ozone concentration in air
barplot(airquality$Ozone, main = 'Ozone Concenteration in air',
xlab = 'ozone levels', col ='blue', horiz = FALSE)
# Histogram for Maximum Daily Temperature
errors in r
##log(-1)
try(log("not a number"),silent=TRUE)
print("errors can't stop me")
##Use tryCatch to handle errors
an.error.occured <- FALSE
tryCatch( { result <- log("not a number"); print(res) }
, error = function(e) {an.error.occured <<- TRUE})
print(an.error.occured)
##tryCatch can handle all conditions 1/2
tryCatch( { result <- log(-1); print(result) }
P NO 7 Q1
library("ggplot2")
data(airquality$Ozone)
head(airquality$Ozone)
#Ozone concentration in air
barplot(airquality$Ozone,
main='Ozone concentration in air',
xlab='ozone levels',horiz=FALSE)
barplot(airquality$Ozone,
main='Ozone concentration in air',
xlab='ozone levels',horiz=TRUE)
P no 6 Q2
input <- mtcars[,c("mpg","disp","hp","wt")]
# Create the relationship model.
model <- lm(mpg~disp+hp+wt, data = input)
# Show the model.
input <- mtcars[,c("mpg","disp","hp","wt")]
# Create the relationship model.
model <- lm(mpg~disp+hp+wt, data = input)
# Show the model.
print(model)
regr 1
x<-c(3,5,7,9,11,15)
y<-c(9,12,16,14,15,66)
print(lm(y~x))
plot(x,y,main="the linear regression",abline(lm(y~x)))
tibble
library(tibble)
(df1 <- tibble(
g = c(1, 2, 3),
data = list(
tibble(x = 1, y = 2),
tibble(x = 4:5, y = 6:7),
tibble(x = 10)
)
))
pipe
df <- data.frame(
id = c(10,11,12,13),
name = c('sai,ram,deepika,sahithi'),
gender = c('M','M','F','F'),
dob = as.Date(c('1990-10-02','1981-3-24','1987-6-14','1985-8-16')),
state = c('CA','NY',NA,NA),
row.names=c('r1','r2','r3','r4')
)
5 p
show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| company |
| fycsdemo1 |
| fycsdemo56 |
| fyds |
| joins |
p no 5
show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| fycsdemo1 |
| fyds |
| joins |
| logindb |
| logindb22 |
P No 5
show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| fycsdemo1 |
| fyds |
| joins |
| logindb |
| logindb22 |
Create a table in r without external file
# create matrix with 4 columns and 4 rows
data= matrix(c(1:16), ncol=4, byrow=TRUE)
# specify the column names and row names of matrix
colnames(data) = c('col1','col2','col3','col4')
tibble
library(tibble)
tibble(x=1:5,y=1:5,z=x^2+y)
tibble(a="Rushali",b="Galande")
tibble()
tibble(mtcars)
tibble(iris)
tibble(head(iris))
options(tibble.print_min=20)
tibble(mtcars,options(tibble.print_min=20))
tibble(iris,options(tibble.print_min=30))
Morechart
library (ggplot2)
library (dplyr)
data(mtcars)
dim(mtcars)
head(mtcars)
mtcars%>%dplyr::group_by(cyl)%>% dplyr::summarize(mpg=median(mpg))%>%ggplot(aes(x=cyl,y=mpg))+geom_col(aes(fill=cyl),color=NA)+labs(x="",y="Median mpg")+coord_polar()
ggplot(mtcars,aes(x=hp,y=mpg,group=cyl))+geom_line(aes(color=cyl),size=2)+geom_point(aes(color=cyl),size=4)+scale_y_reverse(breaks=1:nrow(mtcars))
Contour plot
library (ggplot2)
library(dplyr)
data(mtcars)
ggplot(mtcars,aes(mpg,hp))+geom_density_2d_filled(show.legend=FALSE)+coord_cartesian(expand=FALSE)+labs(x="mpg")
ggplot(mtcars,aes(x=mpg,y=hp))+geom_point()+geom_density_2d()