试图重新调整我在reddit上发现的政治调查代码,以获得更小的样本量。
我正在使用geom_jitter创建一个散点图。这是我的代码:
ggplot(sae, aes(Alignment, Abortion))+
geom_jitter(aes(color = "green"), size = 4, alpha = 0.6)+
labs("Alignment", "Stance on Abortion")
如何围绕" Pro-choice"进行分组?或者" Pro-life"线条更严格?我相信这个当前的图表会让很多人混淆哪些观察是支持选择还是支持生命。
帮助解决颜色问题的额外功劳。
答案 0 :(得分:2)
您可以在width
中设置position = position_jitter()
参数,以控制积分的紧密程度。
ggplot(sae, aes(Alignment, Abortion)) +
geom_jitter(color = "green", size = 4, alpha = 0.6, position = position_jitter(width = .2)) +
labs("Alignment", "Stance on Abortion")
如果您使用的是ggplot2(1.0.1.9003)的最新开发版本,则可以改为geom_jitter(width = .2, ...)
。
如果它仍然太宽,请将width
减少到较小的值(反之亦然)。另请注意,要更改点的颜色,我删除了aes()
周围的color = "green"
。
答案 1 :(得分:2)
你有一个更大的问题。 x轴按字母顺序排列,这非常令人困惑,可能不是你想要的。此外,您可能需要同时指定width
(x方向抖动)和height
(y方向抖动)。
您可以使用例如
修复排序sae$Alignment <- factor(sae$Alignment, levels=unique(sae$Alignment))
如下所示。
# make up some data - you have this already
set.seed(1) # for reproducible example
sae <- data.frame(Alignment=rep(c("Left","Left Leaning","Center","Right Leaning","Right"),each=5),
Abortion =sample(c("Pro Choice","Pro Life","Other"),25, replace=TRUE))
# you start here...
library(ggplot2)
sae$Alignment <- factor(sae$Alignment, levels=unique(sae$Alignment))
ggplot(sae, aes(Alignment, Abortion))+
geom_point(color = "green", size = 4, alpha = 0.6, position=position_jitter(width=0.1, height=0.1))+
labs("Alignment", "Stance on Abortion")
另外,IMO,你可以做得更好。颜色:
sae$Orientation <- with(sae,ifelse(grepl("Left",Alignment),"Progressive",
ifelse(grepl("Right",Alignment),"Conservative","Neutral")))
ggplot(sae, aes(x=Alignment, y=Abortion, color=Orientation))+
geom_point(size = 4, alpha = 0.6, position=position_jitter(width=0.1, height=0.1))+
labs("Alignment", "Stance on Abortion")
答案 2 :(得分:0)
最近才遇到此问题,以上答案均未提供最佳解决方案。
我在库(geom_beeswarm)中使用geom_beeswarm找到了一个绝妙的答案,并认为我应该将其发布在这里。
使用mpg使用geom_jitter进行再现非常混乱:
In file included from C:\Users\Admin\Documents\ArduinoData\packages\arduino\tools\CMSIS-Atmel\1.2.0/CMSIS/Device/ATMEL/samd21/include/samd21.h:69:0,
from C:\Users\Admin\Documents\ArduinoData\packages\arduino\tools\CMSIS-Atmel\1.2.0/CMSIS/Device/ATMEL/samd.h:105,
from C:\Users\Admin\Documents\ArduinoData\packages\arduino\tools\CMSIS-Atmel\1.2.0/CMSIS/Device/ATMEL/sam.h:540,
from C:\Users\Admin\Documents\ArduinoData\packages\arduino\hardware\samd\1.8.9\cores\arduino/Arduino.h:48,
from C:\Users\Admin\Documents\Arduino\libraries\WiFiNINA\src/WiFiClient.h:23,
from C:\Users\Admin\Documents\Arduino\libraries\WiFiNINA\src\utility/wifi_drv.h:28,
from C:\Users\Admin\Documents\Arduino\libraries\WiFiNINA\src\WiFiClient.cpp:30:
C:\Users\Admin\Documents\ArduinoData\packages\arduino\tools\CMSIS-Atmel\1.2.0/CMSIS/Device/ATMEL/samd21/include/samd21g18a.h:226:0: warning: "LITTLE_ENDIAN" redefined
#define LITTLE_ENDIAN 1
In file included from c:\users\admin\documents\arduinodata\packages\arduino\tools\arm-none-eabi-gcc\7-2017q4\arm-none-eabi\include\sys\types.h:67:0,
from c:\users\admin\documents\arduinodata\packages\arduino\tools\arm-none-eabi-gcc\7-2017q4\arm-none-eabi\include\stdio.h:61,
from C:\Users\Admin\Documents\Arduino\libraries\WiFiNINA\src\utility/debug.h:31,
from C:\Users\Admin\Documents\Arduino\libraries\WiFiNINA\src\WiFiClient.cpp:25:
c:\users\admin\documents\arduinodata\packages\arduino\tools\arm-none-eabi-gcc\7-2017q4\arm-none-eabi\include\machine\endian.h:17:0: note: this is the location of the previous definition
#define LITTLE_ENDIAN _LITTLE_ENDIAN
In file included from C:\Users\Admin\Documents\ArduinoData\packages\arduino\tools\CMSIS-Atmel\1.2.0/CMSIS/Device/ATMEL/samd21/include/samd21.h:69:0,
from C:\Users\Admin\Documents\ArduinoData\packages\arduino\tools\CMSIS-Atmel\1.2.0/CMSIS/Device/ATMEL/samd.h:105,
from C:\Users\Admin\Documents\ArduinoData\packages\arduino\tools\CMSIS-Atmel\1.2.0/CMSIS/Device/ATMEL/sam.h:540,
from C:\Users\Admin\Documents\ArduinoData\packages\arduino\hardware\samd\1.8.9\cores\arduino/Arduino.h:48,
from C:\Users\Admin\Documents\Arduino\libraries\WiFiNINA\src\WiFiClient.h:23,
from C:\Users\Admin\Documents\Arduino\libraries\WiFiNINA\src\WiFi.h:34,
from C:\Users\Admin\Documents\Arduino\libraries\WiFiNINA\src\WiFiServer.cpp:28:
C:\Users\Admin\Documents\ArduinoData\packages\arduino\tools\CMSIS-Atmel\1.2.0/CMSIS/Device/ATMEL/samd21/include/samd21g18a.h:226:0: warning: "LITTLE_ENDIAN" redefined
#define LITTLE_ENDIAN 1
In file included from c:\users\admin\documents\arduinodata\packages\arduino\tools\arm-none-eabi-gcc\7-2017q4\arm-none-eabi\include\sys\types.h:67:0,
from c:\users\admin\documents\arduinodata\packages\arduino\tools\arm-none-eabi-gcc\7-2017q4\arm-none-eabi\include\stdio.h:61,
from C:\Users\Admin\Documents\Arduino\libraries\WiFiNINA\src\utility/debug.h:31,
from C:\Users\Admin\Documents\Arduino\libraries\WiFiNINA\src\WiFiServer.cpp:25:
c:\users\admin\documents\arduinodata\packages\arduino\tools\arm-none-eabi-gcc\7-2017q4\arm-none-eabi\include\machine\endian.h:17:0: note: this is the location of the previous definition
#define LITTLE_ENDIAN _LITTLE_ENDIAN
In file included from C:\Users\Admin\Documents\ArduinoData\packages\arduino\tools\CMSIS-Atmel\1.2.0/CMSIS/Device/ATMEL/samd21/include/samd21.h:69:0,
from C:\Users\Admin\Documents\ArduinoData\packages\arduino\tools\CMSIS-Atmel\1.2.0/CMSIS/Device/ATMEL/samd.h:105,
from C:\Users\Admin\Documents\ArduinoData\packages\arduino\tools\CMSIS-Atmel\1.2.0/CMSIS/Device/ATMEL/sam.h:540,
from C:\Users\Admin\Documents\ArduinoData\packages\arduino\hardware\samd\1.8.9\cores\arduino/Arduino.h:48,
from C:\Users\Admin\Documents\Arduino\libraries\WiFiNINA\src/WiFiClient.h:23,
from C:\Users\Admin\Documents\Arduino\libraries\WiFiNINA\src\utility/wifi_drv.h:28,
from C:\Users\Admin\Documents\Arduino\libraries\WiFiNINA\src\WiFi.cpp:21:
C:\Users\Admin\Documents\ArduinoData\packages\arduino\tools\CMSIS-Atmel\1.2.0/CMSIS/Device/ATMEL/samd21/include/samd21g18a.h:226:0: warning: "LITTLE_ENDIAN" redefined
#define LITTLE_ENDIAN 1
In file included from c:\users\admin\documents\arduinodata\packages\arduino\tools\arm-none-eabi-gcc\7-2017q4\arm-none-eabi\include\sys\types.h:67:0,
from c:\users\admin\documents\arduinodata\packages\arduino\tools\arm-none-eabi-gcc\7-2017q4\arm-none-eabi\include\stdio.h:61,
from C:\Users\Admin\Documents\ArduinoData\packages\arduino\hardware\samd\1.8.9\cores\arduino/Print.h:23,
from C:\Users\Admin\Documents\ArduinoData\packages\arduino\hardware\samd\1.8.9\cores\arduino/Stream.h:26,
from C:\Users\Admin\Documents\ArduinoData\packages\arduino\hardware\samd\1.8.9\cores\arduino/Udp.h:38,
from C:\Users\Admin\Documents\Arduino\libraries\WiFiNINA\src/WiFiUdp.h:24,
from C:\Users\Admin\Documents\Arduino\libraries\WiFiNINA\src\utility/wifi_drv.h:27,
from C:\Users\Admin\Documents\Arduino\libraries\WiFiNINA\src\WiFi.cpp:21:
c:\users\admin\documents\arduinodata\packages\arduino\tools\arm-none-eabi-gcc\7-2017q4\arm-none-eabi\include\machine\endian.h:17:0: note: this is the location of the previous definition
#define LITTLE_ENDIAN _LITTLE_ENDIAN
In file included from C:\Users\Admin\Documents\ArduinoData\packages\arduino\tools\CMSIS-Atmel\1.2.0/CMSIS/Device/ATMEL/samd21/include/samd21.h:69:0,
from C:\Users\Admin\Documents\ArduinoData\packages\arduino\tools\CMSIS-Atmel\1.2.0/CMSIS/Device/ATMEL/samd.h:105,
from C:\Users\Admin\Documents\ArduinoData\packages\arduino\tools\CMSIS-Atmel\1.2.0/CMSIS/Device/ATMEL/sam.h:540,
from C:\Users\Admin\Documents\ArduinoData\packages\arduino\hardware\samd\1.8.9\cores\arduino/Arduino.h:48,
from C:\Users\Admin\Documents\Arduino\libraries\WiFiNINA\src/WiFiClient.h:23,
from C:\Users\Admin\Documents\Arduino\libraries\WiFiNINA\src\utility/wifi_drv.h:28,
from C:\Users\Admin\Documents\Arduino\libraries\WiFiNINA\src\WiFiStorage.h:23,
from C:\Users\Admin\Documents\Arduino\libraries\WiFiNINA\src\WiFiStorage.cpp:20:
C:\Users\Admin\Documents\ArduinoData\packages\arduino\tools\CMSIS-Atmel\1.2.0/CMSIS/Device/ATMEL/samd21/include/samd21g18a.h:226:0: warning: "LITTLE_ENDIAN" redefined
#define LITTLE_ENDIAN 1
In file included from c:\users\admin\documents\arduinodata\packages\arduino\tools\arm-none-eabi-gcc\7-2017q4\arm-none-eabi\include\sys\types.h:67:0,
from c:\users\admin\documents\arduinodata\packages\arduino\tools\arm-none-eabi-gcc\7-2017q4\arm-none-eabi\include\stdio.h:61,
from C:\Users\Admin\Documents\ArduinoData\packages\arduino\hardware\samd\1.8.9\cores\arduino/Print.h:23,
from C:\Users\Admin\Documents\ArduinoData\packages\arduino\hardware\samd\1.8.9\cores\arduino/Stream.h:26,
from C:\Users\Admin\Documents\ArduinoData\packages\arduino\hardware\samd\1.8.9\cores\arduino/Udp.h:38,
from C:\Users\Admin\Documents\Arduino\libraries\WiFiNINA\src/WiFiUdp.h:24,
from C:\Users\Admin\Documents\Arduino\libraries\WiFiNINA\src\utility/wifi_drv.h:27,
from C:\Users\Admin\Documents\Arduino\libraries\WiFiNINA\src\WiFiStorage.h:23,
from C:\Users\Admin\Documents\Arduino\libraries\WiFiNINA\src\WiFiStorage.cpp:20:
c:\users\admin\documents\arduinodata\packages\arduino\tools\arm-none-eabi-gcc\7-2017q4\arm-none-eabi\include\machine\endian.h:17:0: note: this is the location of the previous definition
#define LITTLE_ENDIAN _LITTLE_ENDIAN
In file included from C:\Users\Admin\Documents\ArduinoData\packages\arduino\tools\CMSIS-Atmel\1.2.0/CMSIS/Device/ATMEL/samd21/include/samd21.h:69:0,
from C:\Users\Admin\Documents\ArduinoData\packages\arduino\tools\CMSIS-Atmel\1.2.0/CMSIS/Device/ATMEL/samd.h:105,
from C:\Users\Admin\Documents\ArduinoData\packages\arduino\tools\CMSIS-Atmel\1.2.0/CMSIS/Device/ATMEL/sam.h:540,
from C:\Users\Admin\Documents\ArduinoData\packages\arduino\hardware\samd\1.8.9\cores\arduino/Arduino.h:48,
from C:\Users\Admin\Documents\Arduino\libraries\WiFiNINA\src/WiFiClient.h:23,
from C:\Users\Admin\Documents\Arduino\libraries\WiFiNINA\src\utility/wifi_drv.h:28,
from C:\Users\Admin\Documents\Arduino\libraries\WiFiNINA\src\WiFiUdp.cpp:29:
C:\Users\Admin\Documents\ArduinoData\packages\arduino\tools\CMSIS-Atmel\1.2.0/CMSIS/Device/ATMEL/samd21/include/samd21g18a.h:226:0: warning: "LITTLE_ENDIAN" redefined
#define LITTLE_ENDIAN 1
In file included from c:\users\admin\documents\arduinodata\packages\arduino\tools\arm-none-eabi-gcc\7-2017q4\arm-none-eabi\include\sys\types.h:67:0,
from c:\users\admin\documents\arduinodata\packages\arduino\tools\arm-none-eabi-gcc\7-2017q4\arm-none-eabi\include\stdio.h:61,
from C:\Users\Admin\Documents\Arduino\libraries\WiFiNINA\src\utility/debug.h:31,
from C:\Users\Admin\Documents\Arduino\libraries\WiFiNINA\src\WiFiUdp.cpp:24:
c:\users\admin\documents\arduinodata\packages\arduino\tools\arm-none-eabi-gcc\7-2017q4\arm-none-eabi\include\machine\endian.h:17:0: note: this is the location of the previous definition
#define LITTLE_ENDIAN _LITTLE_ENDIAN
In file included from C:\Users\Admin\Documents\ArduinoData\packages\arduino\tools\CMSIS-Atmel\1.2.0/CMSIS/Device/ATMEL/samd21/include/samd21.h:69:0,
from C:\Users\Admin\Documents\ArduinoData\packages\arduino\tools\CMSIS-Atmel\1.2.0/CMSIS/Device/ATMEL/samd.h:105,
from C:\Users\Admin\Documents\ArduinoData\packages\arduino\tools\CMSIS-Atmel\1.2.0/CMSIS/Device/ATMEL/sam.h:540,
from C:\Users\Admin\Documents\ArduinoData\packages\arduino\hardware\samd\1.8.9\cores\arduino/Arduino.h:48,
from C:\Users\Admin\Documents\Arduino\libraries\WiFiNINA\src\utility\wifi_drv.cpp:25:
C:\Users\Admin\Documents\ArduinoData\packages\arduino\tools\CMSIS-Atmel\1.2.0/CMSIS/Device/ATMEL/samd21/include/samd21g18a.h:226:0: warning: "LITTLE_ENDIAN" redefined
#define LITTLE_ENDIAN 1
In file included from c:\users\admin\documents\arduinodata\packages\arduino\tools\arm-none-eabi-gcc\7-2017q4\arm-none-eabi\include\sys\types.h:67:0,
from c:\users\admin\documents\arduinodata\packages\arduino\tools\arm-none-eabi-gcc\7-2017q4\arm-none-eabi\include\stdio.h:61,
from C:\Users\Admin\Documents\Arduino\libraries\WiFiNINA\src\utility\wifi_drv.cpp:21:
c:\users\admin\documents\arduinodata\packages\arduino\tools\arm-none-eabi-gcc\7-2017q4\arm-none-eabi\include\machine\endian.h:17:0: note: this is the location of the previous definition
#define LITTLE_ENDIAN _LITTLE_ENDIAN
C:\Users\Admin\Documents\Arduino\libraries\WiFiNINA\src\utility\spi_drv.cpp: In static member function 'static void SpiDrv::begin()':
C:\Users\Admin\Documents\Arduino\libraries\WiFiNINA\src\utility\spi_drv.cpp:97:15: error: 'NINA_GPIO0' was not declared in this scope
pinMode(NINA_GPIO0, OUTPUT);
^~~~~~~~~~
C:\Users\Admin\Documents\Arduino\libraries\WiFiNINA\src\utility\spi_drv.cpp:97:15: note: suggested alternative: 'PIN_PB10'
pinMode(NINA_GPIO0, OUTPUT);
^~~~~~~~~~
PIN_PB10
C:\Users\Admin\Documents\Arduino\libraries\WiFiNINA\src\utility\spi_drv.cpp: In static member function 'static int SpiDrv::available()':
C:\Users\Admin\Documents\Arduino\libraries\WiFiNINA\src\utility\spi_drv.cpp:581:25: error: 'NINA_GPIO0' was not declared in this scope
return (digitalRead(NINA_GPIO0) != LOW);
^~~~~~~~~~
C:\Users\Admin\Documents\Arduino\libraries\WiFiNINA\src\utility\spi_drv.cpp:581:25: note: suggested alternative: 'PIN_PB10'
return (digitalRead(NINA_GPIO0) != LOW);
^~~~~~~~~~
PIN_PB10
exit status 1
Error compiling for board Arduino MKR NB 1500.```
[1]: https://create.arduino.cc/projecthub/Arduino_Genuino/securely-connecting-an-arduino-mkr-wifi-1010-to-aws-iot-core-a9f365
geom_beeswarm使抖动点集中且清晰得多:
CustomPaint