简体   繁体   中英

How to create a range plot in r

I would like to create a chart similar to this:

在此处输入图像描述

The x-axis is general_perception_very_negative and general_perception_very_positive columns. This question was asked on a slider from 0-10, where 0 on the very negative column means 1 on the very positive column. If 0.75 on the very positive it means 0.25 on the very negative . So the total between the 2 columns is 1.

Below is the dataset:

structure(list(ï..participant_id = c(24260L, 24262L, 24263L, 
                                     24264L, 24265L, 24266L, 24267L, 24268L, 24269L, 24270L, 24271L, 
                                     24272L, 24273L, 24275L, 24278L, 24279L, 24282L, 24283L, 24285L, 
                                     24286L, 24287L, 24288L, 24289L, 24290L, 24292L, 24294L, 24296L, 
                                     24298L, 24299L, 24300L, 24301L, 24302L, 24303L, 24304L, 24305L, 
                                     24307L, 24309L, 24310L, 24314L, 24328L, 24329L, 24330L, 24331L, 
                                     24332L, 24333L, 24334L, 24335L, 24336L, 24337L, 24338L, 24339L, 
                                     24340L, 24341L, 24342L, 24343L, 24344L, 24356L, 24358L, 24360L, 
                                     24362L, 24363L, 24364L, 24366L, 24368L, 24370L, 24373L, 24375L, 
                                     24378L, 24380L, 24382L, 24384L, 24386L, 24388L, 24390L, 24392L, 
                                     24393L, 24395L, 24397L, 24399L, 24401L, 24404L, 24406L, 24408L, 
                                     24410L, 24412L, 24416L, 24418L, 24420L, 24422L, 24427L, 24429L, 
                                     24431L, 24435L, 24437L, 24439L, 24443L, 24445L, 24449L, 24454L, 
                                     24456L, 24457L, 24458L, 24459L, 24461L, 24462L, 24463L, 24464L, 
                                     24467L, 24468L, 24469L, 24476L, 24482L, 24484L, 24486L, 24502L, 
                                     24503L, 24527L, 24528L, 24529L, 24533L, 24535L, 24536L, 24538L, 
                                     24539L, 24541L, 24543L, 24547L, 24548L, 24549L, 24555L, 24559L, 
                                     24560L, 24562L, 24564L, 24565L, 24567L, 24568L, 24569L, 24570L, 
                                     24571L, 24572L, 24573L, 24574L, 24575L, 24579L, 24693L, 24694L, 
                                     24695L, 24697L, 24699L, 24701L, 24703L, 24704L, 24707L, 24708L, 
                                     24709L, 24711L, 24713L, 24715L, 24717L, 24719L, 24721L, 24723L, 
                                     24725L, 24727L, 24729L, 24731L, 24733L, 24735L, 24737L, 24739L, 
                                     24740L, 24742L, 24744L, 24748L, 24749L, 24750L, 24752L, 24755L, 
                                     24758L, 24761L, 24762L, 24764L, 24766L, 24768L, 24770L, 24772L, 
                                     24863L, 24864L, 24865L, 24866L, 24867L, 24868L, 24869L, 24870L, 
                                     24885L, 24886L, 24887L, 24888L, 24889L, 24891L, 24971L, 24972L, 
                                     24973L, 24974L, 24976L, 24978L, 24982L, 24984L, 24986L, 24991L, 
                                     24994L, 24995L, 24996L, 24999L, 25001L, 25002L, 25005L, 25006L, 
                                     25007L, 25009L, 25010L, 25011L, 25012L, 25014L, 25015L, 25016L, 
                                     25017L, 25019L, 25021L, 25024L, 25030L, 25091L, 25092L, 25093L, 
                                     25094L, 25104L, 25105L, 25106L, 25108L, 25109L, 25110L, 25111L, 
                                     25112L, 25114L, 25121L, 25135L, 25136L, 25138L, 25139L, 25140L, 
                                     25157L, 25159L, 25160L, 25161L, 25162L, 25163L, 25165L, 25166L, 
                                     25167L, 25168L, 25169L, 25170L, 25172L, 25174L, 25175L, 25176L, 
                                     25177L, 25179L, 25180L, 25182L, 25189L, 25248L, 25249L, 25252L, 
                                     25253L, 25294L, 25295L, 25296L, 25297L, 25298L, 25302L, 25303L, 
                                     25304L, 25305L, 25306L, 25307L, 25308L, 25309L, 25315L, 25323L, 
                                     25325L, 25327L, 25339L, 25341L, 25343L, 25345L, 25346L, 25348L, 
                                     25349L, 25350L, 25557L, 25559L, 25561L, 25562L, 25563L, 25565L, 
                                     25566L, 25567L, 25569L, 25570L, 25571L, 25573L, 25575L, 25577L, 
                                     25579L, 25581L, 25583L, 25585L, 25586L, 25588L, 25590L, 25591L, 
                                     25592L, 25594L, 25598L, 25601L, 25603L, 25605L, 25608L, 25610L, 
                                     25612L, 25614L, 25616L, 25618L, 25620L, 25622L, 25626L, 25630L, 
                                     25631L, 25632L, 25634L, 25635L, 25638L, 25639L, 25640L, 25641L, 
                                     25642L, 25643L, 25669L, 25670L, 25671L, 25672L, 25673L, 25674L, 
                                     25676L, 25677L, 25684L, 25686L, 25688L, 25691L, 25693L, 25695L, 
                                     25700L, 25704L, 25706L, 24211L, 24212L, 24213L, 24214L, 24215L, 
                                     24216L, 24217L, 24218L, 24219L, 24220L, 24221L, 24222L, 24224L, 
                                     24225L, 24226L, 24227L, 24228L, 24229L, 24230L, 24231L, 24232L, 
                                     24233L, 24234L, 24235L, 24236L, 24237L, 24238L, 24239L, 24240L, 
                                     24243L, 24244L, 24246L, 24247L, 24249L, 24250L, 24251L, 24252L
), general_perception_very_negative = c(0.75999999, 0.819999993, 
                                        1, 1, 0.25999999, 1, 0.720000029, 0.75, 0.600000024, 1, 0.720000029, 
                                        1, 1, 1, 0.709999979, 0.839999974, 0.879999995, 1, 0.779999971, 
                                        0.720000029, 0.939999998, 0.709999979, 0.649999976, 0.74000001, 
                                        0.680000007, 1, 0.209999993, 1, 1, 1, 1, 1, 1, 0.730000019, 1, 
                                        0.25999999, 0.75, 1, 1, 1, 1, 1, 1, 1, 0.720000029, 0.709999979, 
                                        1, 1, 1, 1, 0.930000007, 0.839999974, 0.400000006, 0.75999999, 
                                        0.090000004, 0.050000001, 0.720000029, 0.189999998, 0.270000011, 
                                        0.25, 0.74000001, 0.25999999, 0.340000004, 0.219999999, 0.819999993, 
                                        0.730000019, 0.079999998, 0.670000017, 0.810000002, 0.709999979, 
                                        0.879999995, 0.079999998, 0.550000012, 0.910000026, 0.159999996, 
                                        0.689999998, 0.769999981, 0.200000003, 0.899999976, 0.109999999, 
                                        0.920000017, 0.479999989, 0.449999988, 0.689999998, 0.159999996, 
                                        0.810000002, 0.090000004, 0.790000021, 0.560000002, 0.860000014, 
                                        0.660000026, 0.870000005, 0.810000002, 0.680000007, 0.469999999, 
                                        0.699999988, 0.119999997, 0.720000029, 0.129999995, 0.810000002, 
                                        0.819999993, 0.25999999, 0.879999995, 0.109999999, 0.209999993, 
                                        0.07, 0.209999993, 0.180000007, 0.079999998, 0.75999999, 0.109999999, 
                                        0, 0.25, 0.720000029, 0.870000005, 0.769999981, 0.119999997, 
                                        0.839999974, 0.860000014, 0.850000024, 0.920000017, 0.730000019, 
                                        0.720000029, 0.109999999, 1, 1, 0.670000017, 0.75, 1, 0.889999986, 
                                        0.270000011, 0.800000012, 1, 0.839999974, 1, 0.109999999, 0.230000004, 
                                        0.300000012, 0.280000001, 0.300000012, 0.129999995, 0.319999993, 
                                        0.699999988, 0.330000013, 0.75, 0.779999971, 0.889999986, 0.170000002, 
                                        0.150000006, 0.119999997, 0.25999999, 0.109999999, 0, 1, 0.280000001, 
                                        0, 0.74000001, 0.550000012, 0.819999993, 0.810000002, 0.800000012, 
                                        0.829999983, 0.829999983, 0.810000002, 0.75, 0.150000006, 0.769999981, 
                                        0.810000002, 0.810000002, 0.850000024, 0.07, 0.829999983, 1, 
                                        0.170000002, 0.839999974, 0.100000001, 1, 1, 0.170000002, 1, 
                                        0.769999981, 1, 0.899999976, 0.109999999, 0.230000004, 1, 0.340000004, 
                                        0.860000014, 0.200000003, 0.790000021, 0.74000001, 0.870000005, 
                                        0.310000002, 0, 0.800000012, 0.629999995, 0.200000003, 0.25, 
                                        0.340000004, 0.689999998, 0.629999995, 0.829999983, 0.119999997, 
                                        0.140000001, 0.129999995, 0.280000001, 0.270000011, 0.769999981, 
                                        0.75, 0.209999993, 0.810000002, 0, 0.819999993, 0.860000014, 
                                        0.219999999, 0.850000024, 0, 0.879999995, 0.779999971, 1, 0.730000019, 
                                        1, 0.74000001, 0.74000001, 1, 1, 0.100000001, 0.209999993, 0.280000001, 
                                        0.219999999, 0.349999994, 0.280000001, 0.850000024, 0.800000012, 
                                        0.839999974, 0.75, 0.319999993, 0.620000005, 0.680000007, 0.230000004, 
                                        0.74000001, 0.680000007, 0.670000017, 0.25, 0.239999995, 0.159999996, 
                                        0.140000001, 0.109999999, 0.180000007, 0.150000006, 0.07, 0.949999988, 
                                        0.769999981, 0.079999998, 0.140000001, 0.889999986, 0.879999995, 
                                        0.07, 0.100000001, 0.300000012, 0.219999999, 0.200000003, 0.109999999, 
                                        0.140000001, 1, 0.189999998, 0.980000019, 0.100000001, 0.189999998, 
                                        1, 0.829999983, 0.059999999, 0.140000001, 0.090000004, 0.660000026, 
                                        0.730000019, 0.639999986, 0.270000011, 0.189999998, 0.720000029, 
                                        0.670000017, 0.639999986, 0.689999998, 0.870000005, 0.810000002, 
                                        0.800000012, 0.889999986, 0.910000026, 0.889999986, 0, 0.090000004, 
                                        0.170000002, 0.119999997, 0.910000026, 0.860000014, 1, 0.860000014, 
                                        0.159999996, 1, 1, 1, 0, 1, 0.230000004, 0.769999981, 0.270000011, 
                                        0.819999993, 1, 0.699999988, 0.779999971, 0.189999998, 0.810000002, 
                                        0.699999988, 0.839999974, 0.800000012, 0.839999974, 0.860000014, 
                                        0.230000004, 0.230000004, 0.720000029, 0.119999997, 0.200000003, 
                                        0, 0.810000002, 0.790000021, 0.180000007, 0.800000012, 0.769999981, 
                                        1, 0.159999996, 0.200000003, 0.25999999, 0.709999979, 0.180000007, 
                                        0.100000001, 0.219999999, 0.810000002, 0.829999983, 1, 1, 1, 
                                        0.99000001, 0.75999999, 0.839999974, 0, 0.230000004, 1, 0, 0.829999983, 
                                        1, 1, 1, 1, 1, 0.879999995, 1, 0.159999996, 0.889999986, 0.219999999, 
                                        1, 1, 0.730000019, 0.75, 0.99000001, 0.970000029, 0.300000012, 
                                        0.829999983, 0.519999981, 0.660000026, 0.219999999, 0.850000024, 
                                        0.150000006, 0.879999995, 1, 0.920000017, 0.709999979, 0.319999993, 
                                        0.879999995, 0.159999996, 1, 0.639999986, 0.850000024, 0.129999995, 
                                        0.129999995, 0.629999995, 0.310000002, 0.639999986, 0.230000004, 
                                        0.200000003, 0.779999971, 0.839999974, 0.790000021, 0.639999986, 
                                        1, 0.819999993, 1, 0.680000007, 0.800000012, 0.75999999, 1, 1, 
                                        0.810000002, 1), general_perception_very_positive = c(0.239999995, 
                                                                                              0.180000007, 0, 0, 0.74000001, 0, 0.280000001, 0.25, 0.400000006, 
                                                                                              0, 0.280000001, 0, 0, 0, 0.289999992, 0.159999996, 0.119999997, 
                                                                                              0, 0.219999999, 0.280000001, 0.059999999, 0.289999992, 0.349999994, 
                                                                                              0.25999999, 0.319999993, 0, 0.790000021, 0, 0, 0, 0, 0, 0, 0.270000011, 
                                                                                              0, 0.74000001, 0.25, 0, 0, 0, 0, 0, 0, 0, 0.280000001, 0.289999992, 
                                                                                              0, 0, 0, 0, 0.07, 0.159999996, 0.600000024, 0.239999995, 0.910000026, 
                                                                                              0.949999988, 0.280000001, 0.810000002, 0.730000019, 0.75, 0.25999999, 
                                                                                              0.74000001, 0.660000026, 0.779999971, 0.180000007, 0.270000011, 
                                                                                              0.920000017, 0.330000013, 0.189999998, 0.289999992, 0.119999997, 
                                                                                              0.920000017, 0.449999988, 0.090000004, 0.839999974, 0.310000002, 
                                                                                              0.230000004, 0.800000012, 0.100000001, 0.889999986, 0.079999998, 
                                                                                              0.519999981, 0.550000012, 0.310000002, 0.839999974, 0.189999998, 
                                                                                              0.910000026, 0.209999993, 0.439999998, 0.140000001, 0.340000004, 
                                                                                              0.129999995, 0.189999998, 0.319999993, 0.529999971, 0.300000012, 
                                                                                              0.879999995, 0.280000001, 0.870000005, 0.189999998, 0.180000007, 
                                                                                              0.74000001, 0.119999997, 0.889999986, 0.790000021, 0.930000007, 
                                                                                              0.790000021, 0.819999993, 0.920000017, 0.239999995, 0.889999986, 
                                                                                              1, 0.75, 0.280000001, 0.129999995, 0.230000004, 0.879999995, 
                                                                                              0.159999996, 0.140000001, 0.150000006, 0.079999998, 0.270000011, 
                                                                                              0.280000001, 0.889999986, 0, 0, 0.330000013, 0.25, 0, 0.109999999, 
                                                                                              0.730000019, 0.200000003, 0, 0.159999996, 0, 0.889999986, 0.769999981, 
                                                                                              0.699999988, 0.720000029, 0.699999988, 0.870000005, 0.680000007, 
                                                                                              0.300000012, 0.670000017, 0.25, 0.219999999, 0.109999999, 0.829999983, 
                                                                                              0.850000024, 0.879999995, 0.74000001, 0.889999986, 1, 0, 0.720000029, 
                                                                                              1, 0.25999999, 0.449999988, 0.180000007, 0.189999998, 0.200000003, 
                                                                                              0.170000002, 0.170000002, 0.189999998, 0.25, 0.850000024, 0.230000004, 
                                                                                              0.189999998, 0.189999998, 0.150000006, 0.930000007, 0.170000002, 
                                                                                              0, 0.829999983, 0.159999996, 0.899999976, 0, 0, 0.829999983, 
                                                                                              0, 0.230000004, 0, 0.100000001, 0.889999986, 0.769999981, 0, 
                                                                                              0.660000026, 0.140000001, 0.800000012, 0.209999993, 0.25999999, 
                                                                                              0.129999995, 0.689999998, 1, 0.200000003, 0.370000005, 0.800000012, 
                                                                                              0.75, 0.660000026, 0.310000002, 0.370000005, 0.170000002, 0.879999995, 
                                                                                              0.860000014, 0.870000005, 0.720000029, 0.730000019, 0.230000004, 
                                                                                              0.25, 0.790000021, 0.189999998, 1, 0.180000007, 0.140000001, 
                                                                                              0.779999971, 0.150000006, 1, 0.119999997, 0.219999999, 0, 0.270000011, 
                                                                                              0, 0.25999999, 0.25999999, 0, 0, 0.899999976, 0.790000021, 0.720000029, 
                                                                                              0.779999971, 0.649999976, 0.720000029, 0.150000006, 0.200000003, 
                                                                                              0.159999996, 0.25, 0.680000007, 0.379999995, 0.319999993, 0.769999981, 
                                                                                              0.25999999, 0.319999993, 0.330000013, 0.75, 0.75999999, 0.839999974, 
                                                                                              0.860000014, 0.889999986, 0.819999993, 0.850000024, 0.930000007, 
                                                                                              0.050000001, 0.230000004, 0.920000017, 0.860000014, 0.109999999, 
                                                                                              0.119999997, 0.930000007, 0.899999976, 0.699999988, 0.779999971, 
                                                                                              0.800000012, 0.889999986, 0.860000014, 0, 0.810000002, 0.02, 
                                                                                              0.899999976, 0.810000002, 0, 0.170000002, 0.939999998, 0.860000014, 
                                                                                              0.910000026, 0.340000004, 0.270000011, 0.360000014, 0.730000019, 
                                                                                              0.810000002, 0.280000001, 0.330000013, 0.360000014, 0.310000002, 
                                                                                              0.129999995, 0.189999998, 0.200000003, 0.109999999, 0.090000004, 
                                                                                              0.109999999, 1, 0.910000026, 0.829999983, 0.879999995, 0.090000004, 
                                                                                              0.140000001, 0, 0.140000001, 0.839999974, 0, 0, 0, 1, 0, 0.769999981, 
                                                                                              0.230000004, 0.730000019, 0.180000007, 0, 0.300000012, 0.219999999, 
                                                                                              0.810000002, 0.189999998, 0.300000012, 0.159999996, 0.200000003, 
                                                                                              0.159999996, 0.140000001, 0.769999981, 0.769999981, 0.280000001, 
                                                                                              0.879999995, 0.800000012, 1, 0.189999998, 0.209999993, 0.819999993, 
                                                                                              0.200000003, 0.230000004, 0, 0.839999974, 0.800000012, 0.74000001, 
                                                                                              0.289999992, 0.819999993, 0.899999976, 0.779999971, 0.189999998, 
                                                                                              0.170000002, 0, 0, 0, 0.01, 0.239999995, 0.159999996, 1, 0.769999981, 
                                                                                              0, 1, 0.170000002, 0, 0, 0, 0, 0, 0.119999997, 0, 0.839999974, 
                                                                                              0.109999999, 0.779999971, 0, 0, 0.270000011, 0.25, 0.01, 0.029999999, 
                                                                                              0.699999988, 0.170000002, 0.479999989, 0.340000004, 0.779999971, 
                                                                                              0.150000006, 0.850000024, 0.119999997, 0, 0.079999998, 0.289999992, 
                                                                                              0.680000007, 0.119999997, 0.839999974, 0, 0.360000014, 0.150000006, 
                                                                                              0.870000005, 0.870000005, 0.370000005, 0.689999998, 0.360000014, 
                                                                                              0.769999981, 0.800000012, 0.219999999, 0.159999996, 0.209999993, 
                                                                                              0.360000014, 0, 0.180000007, 0, 0.319999993, 0.200000003, 0.239999995, 
                                                                                              0, 0, 0.189999998, 0), x = 1:403), row.names = c(NA, 403L), class = "data.frame")

I have searched but did not find something close to that.

So here is an approximation of what I interpret to be your question using a histogram.

Assume df is the data you posted:

# simplify columnames for brevity
colnames(df) <- c("id", "neg", "pos", "x")


df <- reshape2::melt(df, id.vars = "id", measure.vars = c("neg", "pos"))

ggplot(df, aes(x = value, fill = variable)) +
  geom_histogram(binwidth = 0.025) # you could change the binwith however you like

在此处输入图像描述

As you can see from the symmetry, there is duplicated information in here. If this is not what you wanted, I recommend you expand your question to include relevant details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM