ETS 638 Data Visulalizaton(PART-II)
Name: Saira Rasul
Roll.No. 2436
Q-2(a)-
My Home city is “Sargodha”
library(ggplot2)
library(leaflet)
my_map <- addMarkers (addTiles(leaflet()), lat= 32.08361 , lng= 72.6711, popup= "Hello form city Sargodha")
my_map
Q-2(b)-
To describe the data before running the graph
- for geom_point(), it will give me the scatter plot with points for “mpg”" data with cty on X-axis and hwy on Y-axis.
- for geom_point(), it will give me the scatter plot with points for “diamonds”" data with carat on X-axis and price on Y-axis.
- for geom_line(), it will give me the scatter plot with points for “economics”" data with date on X-axis and unemploy on Y-axis.
- for geom_histogram(), it will give me the Histogram for “mpg” data.
Now, to draw the graphs
ggplot(mpg, aes(cty, hwy)) + geom_point()

ggplot(diamonds, aes(carat, price))+ geom_point()

ggplot(economics, aes(date, unemploy))+ geom_line()

ggplot(mpg, aes(cty))+ geom_histogram()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

our Histogram is Positively skewd here, which is clear after running the graph.
Q-2(c)-
What happens if you map a continuous variable to shape? Why? What happens if you map trans to shape? Why?
Answer:
If we just try to draw the graph of a contiunous variable, two continuous variables are easy to graph. But with 3rd continuous variable, we must use it as “colour” or “size” to make the aesthetic. Most of the time “X & Y” are high frequency data. for #rd variable to be continuous, we must firstly changwe it into the factor variable than it will change the shape or size in the graph.
Q-2(d)-
What arguments can you use to contro; how many and columns appear in the output?
Q-2(e)-
Re-create the R code to produce the foolowing graphs.
the graphs are already created after giving the reasons in Part- 2(b)
Q-3-
setup
options(scipen=999)
library(ggplot2)
data("midwest", package= "ggplot2")
ggplot(midwest, aes(x=area, y=poptotal))

Q-3-(i)
Hiow to Make a simple scatterplot of area and poptotal. Add plot tilte, meaningful axis labels etc.
ggplot(midwest, aes(x=area, y=poptotal)) + geom_line() + geom_point()

Q-3-(ii)
Most of the points are concentrated on the bottom portion of the plot, which is not so nice, how will you rectify these? draw.
ggplot(midwest, aes(x=area, y=poptotal)) + geom_point( shape=21, size=2.5) + scale_fill_gradient(low= "black", high= "white", breaks=12:17, guide=guide_legend())

Q-3-(iii)
How to change the colour and size of points?
ggplot(midwest, aes(x=area, y=poptotal)) + geom_point( shape=21, size=2.5) + scale_fill_gradient(low= "black", high= "white")

ggplot(midwest, aes(x=area, y=poptotal)) + geom_point( shape=21, size=5) + scale_fill_gradient(low= "black", high= "white")

By changing the values of shape and size, we arew able to change the color and size of the graphs.
Q-3-(iv)
How to change the color to reflect categories in another column? Use varaiable ‘state’ for this purpose.
library(gcookbook)
ggplot(midwest, aes(x=area, y=poptotal)) + geom_point()+ geom_bar(stat="identity", width=0.5)
## Warning: position_stack requires non-overlapping x intervals

Q-3-(v)
How to change the X & Y axis text and its location?
ggplot(midwest, aes(x=area, y=poptotal)) + geom_line()

ggplot(midwest, aes(x=area, y=poptotal)) + geom_line() + coord_flip()

Q-3-(vi)
Why we use Bubble chart? Explain briefly.
Answer:
Ballon plot/ ballon chart is used to construct the graph where dots is proportional to their numeric values. Voilon/ Bubble chart are used to compare density estimates of different groups. They are a way of comparing multiple data distributions. with ordinary density curves, it is difficult to compare more than just a few distributions because the lines visually interface with eachother. with violon. it easier to compare severaL DISTRIBUTIONS SINCE THEY’RE placed side by side.
Q-1- answer:
Its new graph is attached as excel with this file.
- still percentages don’t give us very clear cut evidence about the birth by day bu just simply looking at the graph.
- it makes load on our cognitive ability.
- we have to chane the colors into light grey sgades so it can be easily identified even with black orintout.
- for long labels, just change it into vertical bar chart instead of horizontal chart.
- remove the gridline.
- from right to left, eye movement have less cognitive load on anyone.
- i just use to change it from horizontal to the vertical to reduce the cognitive load here.
- just make it simple to be very clear for even a layman.
- Bar charts are much better over even complex charts because they are easily understandable by the audience.
- if we go for advance charts, than it is difficult for the audience to understand. it will know take time to understand by the audince. so to decrease the time better to use the Bar charts.