翻轉笛卡爾坐標,使水平變為垂直,垂直變為水平。這主要用於將顯示以 x 為條件的 y 的幾何圖形和統計數據轉換為以 y 為條件的 x。
參數
- xlim, ylim
 - 
x 軸和 y 軸的限製。
 - expand
 - 
如果
TRUE(默認值)會在限製中添加一個小的擴展因子,以確保數據和軸不重疊。如果FALSE,則完全從數據或xlim/ylim中獲取限製。 - clip
 - 
是否應該將繪圖裁剪到繪圖麵板的範圍內?設置
"on"(默認)表示是,設置"off"表示否。在大多數情況下,不應更改"on"的默認值,因為設置clip = "off"可能會導致意外結果。它允許在繪圖上的任何位置繪製數據點,包括繪圖邊。如果通過xlim和ylim設置限製,並且某些數據點超出這些限製,則這些數據點可能會顯示在軸、圖例、繪圖標題或繪圖邊距等位置。 
例子
# Very useful for creating boxplots, and other interval
# geoms in the horizontal instead of vertical position.
ggplot(diamonds, aes(cut, price)) +
  geom_boxplot() +
  coord_flip()
h <- ggplot(diamonds, aes(carat)) +
  geom_histogram()
h
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
h + coord_flip()
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
h + coord_flip() + scale_x_reverse()
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
# You can also use it to flip line and area plots:
df <- data.frame(x = 1:5, y = (1:5) ^ 2)
ggplot(df, aes(x, y)) +
  geom_area()
last_plot() + coord_flip()
相關用法
- R ggplot2 coord_fixed 具有固定“縱橫比”的笛卡爾坐標
 - R ggplot2 coord_map Map投影
 - R ggplot2 coord_polar 極坐標
 - R ggplot2 coord_cartesian 笛卡爾坐標
 - R ggplot2 coord_trans 變換後的笛卡爾坐標係
 - R ggplot2 cut_interval 將數值數據離散化為分類數據
 - R ggplot2 annotation_logticks 注釋:記錄刻度線
 - R ggplot2 vars 引用分麵變量
 - R ggplot2 position_stack 將重疊的對象堆疊在一起
 - R ggplot2 geom_qq 分位數-分位數圖
 - R ggplot2 geom_spoke 由位置、方向和距離參數化的線段
 - R ggplot2 geom_quantile 分位數回歸
 - R ggplot2 geom_text 文本
 - R ggplot2 get_alt_text 從繪圖中提取替代文本
 - R ggplot2 annotation_custom 注釋:自定義grob
 - R ggplot2 geom_ribbon 函數區和麵積圖
 - R ggplot2 stat_ellipse 計算法行數據橢圓
 - R ggplot2 resolution 計算數值向量的“分辨率”
 - R ggplot2 geom_boxplot 盒須圖(Tukey 風格)
 - R ggplot2 lims 設置規模限製
 - R ggplot2 geom_hex 二維箱計數的六邊形熱圖
 - R ggplot2 scale_gradient 漸變色階
 - R ggplot2 scale_shape 形狀比例,又稱字形
 - R ggplot2 geom_bar 條形圖
 - R ggplot2 draw_key 圖例的關鍵字形
 
注:本文由純淨天空篩選整理自Hadley Wickham等大神的英文原創作品 Cartesian coordinates with x and y flipped。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
