如何在R中使用ggplot在y轴上扩展值

时间:2020-07-19 04:37:48

标签: r ggplot2

我正在尝试测量美国各政党的8种情绪,但是仅显示4种情绪的数据(我已附上图片)。我如何包含所有感受?我还包括下面的代码和此处的屏幕截图:

ggplot image in R

以下是与数据有关的调查问题和评分量表:

下面是对象可能引起的感觉或情绪的列表。请使用以下来形容美国联邦方(及其民选官员)如何让你感受到列表。如果该词明确描述了聚会的感觉,请选择数字5。如果您确定该词根本不描述聚会的感觉,请选择数字1。使用1到5之间的中间数字表示这两个极端之间的反应。

Rating Scales

我的代码:

ggplot(df) +
  geom_point(aes(mydata2$PARTYID_Strength, mydata2$mean.traitdem, 
                 color = mydata2$mean.traitdem)) +
  ggtitle("Political Party Affiliation and Feelings Towards the National Democratic Party") +
  xlab("Political Party Identification") +
  ylab("Feelings Towards Democratic Party")+
  xlim("Strong Democrat", "Not Very Strong Democrat",
       "Strong Republican", "Not Very Strong Republican",
       "Independent", "Independent - Democrat",
       "Independent - Republican", "Other")+
  ylim("Delighted", "Angry", "Happy", "Annoyed", "Joy", "Hateful", "Relaxed", "Disgusted") +
  theme(legend.position= "right", axis.text.x= element_text(angle = 45, hjust = 0.8))+
    scale_color_continuous(name = "Degrees of Emotion", 
                           breaks = c(1,2,3,4,5),
                           labels = c("1","2","3","4","5")) + 
    theme(legend.key.height = unit(1, "cm"))

我的数据示例:

> dput(head(mydata2, 30))
structure(list(PARTYID = c(1, 3, 1, 1, 1, 4, 3, 1, 1, 1, 1, 1, 
1, 1, 3, 3, 3, 3, 1, 3, 1, 1, 1, 2, 1, 3, 1, 1, 1, 2), PARTYID_Other = 
c("NA", 
"NA", "NA", "NA", "NA", "Green", "NA", "NA", "NA", "NA", "NA", 
"NA", "NA", "NA", "NA", "NA", "NA", "NA", "NA", "NA", "NA", "NA", 
"NA", "NA", "NA", "NA", "NA", "NA", "NA", "NA"), PARTYID_Strength = c(1, 
7, 1, 2, 1, 8, 1, 6, 1, 1, 2, 1, 6, 1, 7, 5, 4, 6, 1, 2, 2, 1, 
2, 3, 1, 5, 2, 2, 6, 3), PARTYID_Strength_Other = c("NA", "NA", 
"NA", "NA", "NA", "Green", "NA", "NA", "NA", "NA", "NA", "NA", 
"NA", "NA", "NA", "NA", "NA", "NA", "NA", "NA", "NA", "NA", "NA", 
"NA", "NA", "NA", "NA", "NA", "NA", "NA"), THERM_Dem = c(80, 
65, 85, 30, 76, 15, 55, 62, 90, 95, 73, 70, 98, 80, 0, 62, 10, 
70, 100, 32, 70, 100, 75, 0, 74, 60, 55, 10, 86, 39), THERM_Rep = c(1, 
45, 10, 5, 14, 14, 0, 4, 10, 3, 0, 0, 37, 10, 70, 38, 50, 31, 
0, 54, 50, 0, 20, 100, 20, 0, 14, 30, 12, 81), Gender = c("Female", 
"Male", "Male", "Female", "Female", "Male", "Male", "Female", 
"Female", "Male", "Female", "Female", "Female", "Non-binary", 
"Male", "Male", "Female", "Male", "Female", "Female", "Female", 
"Female", "Female", "Male", "Female", "Female", "Female", "Female", 
"Female", "Male"), `MEAN Age` = c(29.5, 49.5, 29.5, 39.5, 29.5, 
21, 39.5, 39.5, 29.5, 65, 29.5, 39.5, 65, 59.5, 49.5, 49.5, 39.5, 
29.5, 21, 29.5, 59.5, 21, 39.5, 65, 21, 39.5, 21, 21, 59.5, 65
), Age = c("25 - 34", "45 - 54", "25 - 34", "35 - 44", "25 - 34", 
"18 - 24", "35 - 44", "35 - 44", "25 - 34", "65+", "25 - 34", 
"35 - 44", "65+", "55 - 64", "45 - 54", "45 - 54", "35 - 44", 
"25 - 34", "18 - 24", "25 - 34", "55 - 64", "18 - 24", "35 - 44", 
"65+", "18 - 24", "35 - 44", "18 - 24", "18 - 24", "55 - 64", 
"65+"), Ethnicity = c("White or Caucasian", "Asian or Asian American", 
"White or Caucasian", "White or Caucasian", "Hispanic or Latino", 
"White or Caucasian", "White or Caucasian", "White or Caucasian", 
"White or Caucasian", "White or Caucasian", "White or Caucasian", 
"White or Caucasian", "White or Caucasian", "White or Caucasian", 
"White or Caucasian", "White or Caucasian", "White or Caucasian", 
"Hispanic or Latino", "White or Caucasian", "White or Caucasian", 
"White or Caucasian", "White or Caucasian", "Hispanic or Latino", 
"White or Caucasian", "White or Caucasian", "White or Caucasian", 
"Black or African American", "Black or African American,White or     Caucasian", 
"White or Caucasian", "White or Caucasian"), Ethnicity_Other = c("NA", 
"NA", "NA", "NA", "NA", "NA", "NA", "NA", "NA", "NA", "NA", "NA", 
"NA", "NA", "NA", "NA", "NA", "NA", "NA", "NA", "NA", "NA", "NA", 
"NA", "NA", "NA", "NA", "NA", "NA", "NA"), States = c("Texas", 
"Texas", "Ohio", "Texas", "Puerto Rico", "New Hampshire", "South         Carolina", 
"Texas", "Texas", "Texas", "Ohio", "Ohio", "Michigan", "New Jersey", 
"Texas", "North Carolina", "Florida", "Texas", "South Carolina", 
"Illinois", "New York", "New York", "Texas", "Ohio", "Virginia", 
"North Carolina", "Georgia", "Rhode Island", "Oregon", "Florida"
), Education = c("Master's degree", "Bachelor's degree in college (4-year)", 
"Bachelor's degree in college (4-year)", "Master's degree", "Master's degree", 
"Less than high school degree", "Some college but no degree", 
"Master's degree", "Master's degree", "Some college but no degree", 
"Bachelor's degree in college (4-year)", "Master's degree", "Associate     degree in college (2-year)", 
"Doctoral degree", "Master's degree", "Bachelor's degree in college (4-year)", 
"Some college but no degree", "Master's degree", "Associate degree in college (2-year)", 
"Master's degree", "Some college but no degree", "Bachelor's degree in college (4-year)", 
"Master's degree", "Some college but no degree", "Bachelor's degree in college (4-year)", 
"Master's degree", "Bachelor's degree in college (4-year)", "Bachelor's degree in college (4-year)", 
"Bachelor's degree in college (4-year)", "Bachelor's degree in college (4-    year)"
), `MEAN Income` = c(30000, 140000, 150000, 60000, 80000, 30000, 
30000, 120000, 150000, 60000, 30000, 40000, 40000, 0, 150000, 
150000, 150000, 40000, 150000, 140000, 40000, 1e+05, 1e+05, 1e+05, 
150000, 40000, 150000, 80000, 60000, 80000), Income = c("Less than     $30,000", 
"$130,001 to $150,000", "More than $150,000", "$50,001 to $70,000", 
"$70,001 to $90,000", "Less than $30,000", "Less than $30,000", 
"$110,001 to $130,000", "More than $150,000", "$50,001 to $70,000", 
"Less than $30,000", "$30,000 to $50,000", "$30,000 to $50,000", 
"NA", "More than $150,000", "More than $150,000", "More than $150,000", 
"$30,000 to $50,000", "More than $150,000", "$130,001 to $150,000", 
"$30,000 to $50,000", "$90,001 to $110,000", "$90,001 to $110,000", 
"$90,001 to $110,000", "More than $150,000", "$30,000 to $50,000", 
"More than $150,000", "$70,001 to $90,000", "$50,001 to $70,000", 
"$70,001 to $90,000"), mean.partystrength = c(3.875, 2.875, 2.375, 
3.5, 2.625, 3.125, 3.375, 3.125, 3.25, 3.625, 3.375, 3.5, 2.875, 
3, 2.75, 2.625, 3, 2.5, 3.5, 3.125, 3.25, 3.375, 2.875, 3.125, 
3.125, 3, 2.875, 2.125, 2.375, 3.5), mean.traitrep = c(2.5, 2.625, 
2.25, 2.625, 2.75, 1.875, 2.75, 2.875, 2.75, 3, 2.875, 3, 3.375, 
2, 2.375, 2.375, 1.75, 1.75, 3, 3, 3, 3, 2.375, 3, 2.375, 2.75, 
1.625, 2.625, 2.25, 2.125), mean.traitdem = c(2.25, 2.625, 2.375, 
2.75, 2.625, 2.125, 1.875, 3, 2, 2.5, 2.875, 2.125, 2.75, 2.125, 
3, 2.375, 2.75, 1.75, 2.25, 3, 4, 2.75, 2, 3, 2.75, 2.375, 1.75, 
3.125, 2.375, 2.625), mean.leegauthor = c(1, 2, 2, 4, 1, 4, 1, 
1, 1, 1, 3, 2, 4, 2, 3, 4, 3, 1, 1, 3, 4, 1, 1, 3, 2, 1, 3, 2, 
2, 3), mean.legit = c(1.71428571428571, 3.28571428571429,         2.42857142857143, 
2.42857142857143, 2.14285714285714, 1.28571428571429, 1.42857142857143, 
1.14285714285714, 2.14285714285714, 1.28571428571429, 1.28571428571429, 
2, 2.28571428571429, 3.28571428571429, 2.14285714285714, 1.14285714285714, 
2.14285714285714, 2, 1.57142857142857, 3.28571428571429, 3.57142857142857, 
1.71428571428571, 1.85714285714286, 3.71428571428571, 2.42857142857143, 
1.85714285714286, 2.57142857142857, 3.28571428571429, 1.57142857142857, 
4)), row.names = c(NA, -30L), class = c("tbl_df", "tbl", "data.frame"
))

Original data of traits/emotions

0 个答案:

没有答案