Show large dots when plotting the same values

When I draw the following example:

Participant <- c(1:12)
AnswersDay1 <- c(9,3,9,13,7,12,10,7,9,0,12,11)
Day1Group   <- c(0,1,0,1, 0, 1, 0,1,0,1, 0, 1)


PushFrame <- data.frame(Participant, AnswersDay1, Day1Group)
plot(AnswersDay1, Day1Group)

The plot shows only ten points instead of 12 values ​​in data.frame. I realized that this is due to the fact that there are three pairs with the same value.

Is there any way to illustrate this inside the plot? Could it be that large dots are used when they have the same meaning or something like that?

+4
source share
4 answers

1) sunflowerplot . You may prefer to use a sunflower that displays repeating dots as one dot with a spoke for each occasion. No packages required.

sunflowerplot(AnswersDay1, Day1Group)

(continued after the schedule)

screenshot

2) - , . Y, X , . .

set.seed(123) # set seed of random number generator for reproducibility
plot(AnswersDay1, jitter(Day1Group))

( )

screenshot

3) cex , , ( "" ag), , . , .

ag <- aggregate(Participant ~., PushFrame, length)
plot(Day1Group ~ AnswersDay1, ag, cex = Participant, pch = 20)

screenshot

+6

, theres : cex :

plot(AnswersDay1, Day1Group, cex = point_size)

, ? , table:

tab = table(AnswersDay1, Day1Group)

tab:

           Day1Group
AnswersDay1 0 1
         0  0 1
         3  0 1
         7  1 1
         9  3 0
         10 1 0
         11 0 1
         12 1 1
         13 0 1

, AnswersDay1 , . AnswersDay1 Day1Group:

point_size = diag(tab[as.character(AnswersDay1), as.character(Day1Group)])

as.character - , , . diag , .

+4

scales , ( ):

 library(scales)
 plot(AnswersDay1, Day1Group, pch = 20, cex= 2, col = alpha('black', 0.35))

alpha 1 ( ) 0 ( ).

enter image description here

+3

A couple more possibilities:

@KonradRudolph solution is already implemented in plotrix::sizeplot().

PushFrame <- data.frame(Participant=1:12,
     AnswersDay1=c(9,3,9,13,7,12,10,7,9,0,12,11),
     Day1Group=c(0,1,0,1, 0, 1, 0,1,0,1, 0, 1))


 library(plotrix)
 with(PushFrame,sizeplot(AnswersDay1,Day1Group))

B ggplot2, stat_sum()automatically calculates matching values ​​and scales the size accordingly ...

 library(ggplot2); theme_set(theme_bw())
 ggplot(PushFrame,aes(AnswersDay1,Day1Group))+stat_sum()
+1
source

Source: https://habr.com/ru/post/1618102/


All Articles