Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in R Programming by (50.2k points)

I want to implement an R code to plot a graph of 1⁄4 circle in the 1st quadrant. Points in the circle are red and others are blue. The output should look like the following image:

                                              image

1 Answer

0 votes
by (108k points)

You can refer to the following solution:

library(ggplot2)

library(ggforce)

ggplot() + 

  geom_circle(aes(x0 = 0, y0 = 0, r = 1), fill = 'red', colour = 'red') +

  coord_cartesian(xlim = c(-1, 1), ylim = c(-1, 1), expand = FALSE) +

  geom_hline(yintercept = 0) +

  geom_vline(xintercept = 0) +

  geom_segment(aes(x = 0, y = 0, xend = 0.35, yend = 0.8)) +

  geom_segment(aes(x = 0, y = 0.8, xend = 0.35, yend = 0.8)) +

  geom_segment(aes(x = 0.35, y = 0, xend = 0.35, yend = 0.8)) +

  annotate('text', x = -0.04,y = -0.04, label = '0') +

  annotate('text', x = -0.04,y = 0.94, label = '1') +

  annotate('text', x = 0.94,y = -0.04, label = '1') +

  annotate('text', x = 0.35/2,y = 0.84, label = 'x') +

  annotate('text', x = 0.4,y = 0.4, label = 'y') +

  annotate('text', x = 0.15,y = 0.44, label = 'r') +

  theme(panel.background = element_rect(fill = "blue",

                                    colour = "lightblue"),

        panel.grid.major = element_blank(), 

        panel.grid.minor =element_blank(),

        axis.title.x=element_blank(),

        axis.text.x=element_blank(),

        axis.ticks.x=element_blank(),

        axis.title.y=element_blank(),

        axis.text.y=element_blank(),

        axis.ticks.y=element_blank())

                                                                                                                enter image description here

If you are a beginner and want to know more about R then do check out the R programming tutorial.

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94.1k users

Browse Categories

...